Skip to content

Latest commit

 

History

History
205 lines (136 loc) · 5.73 KB

README.md

File metadata and controls

205 lines (136 loc) · 5.73 KB

Siba project - Backend

This project was created on the courses Softala-projekti / Software Project

Creators

SIBA22S Softala team

SIBA23K Softala team

SWP23K team

SWP24K team

About the project

Copyrights reserved. This Project is a collaborative work, which aims at building an information system that makes it possible to calculate and optimize teaching space and equipment usage for different lessons.

(back to top)

Backend technology and other useful resources

(back to top)

Beginning

Backend side installation instructions

Installation

  1. Install Mariadb version 10.x or newer

  2. Install a Graphical SQL-editor: DBeaver or MySQL Workbench

  3. Create in your chosen SQL editor a database scheme called casedb. Run 000__CreateALLdb.sql script to create files to the database

  4. Clone the repository

    git clone https://github.com/haagahelia/Siba_be.git
  5. Change directory

    cd Siba_be
  6. Install needed packages

    npm install
  7. Create the .env file. Add .env to the root of the project

    BE_API_URL_PREFIX=/api
    BE_SERVER_PORT=3001
    DB_DRIVER_MODULE=mysql
    BE_DEVELOPMENT_PHASE=true
    DB_HOST=localhost
    DB_PORT=3306
    MARIADB_USER=<<DB Username>>
    MARIADB_PASSWORD=<<DB password>>
    MARIADB_ROOT_PASSWORD=<<root password>>  # Needed when running with Docker. Otherwise not needed.
    MARIADB_DATABASE=casedb
    DB_DEBUG=true
    DB_MULTIPLE_STATEMENTS=true
    DB_CONNECTION_POOL_MIN=1
    DB_CONNECTION_POOL_MAX=7
    SECRET_TOKEN=<<Secret token here for the JWT>>
    TOKEN_EXPIRATION_SECONDS=3600
    

    The secret_token has to be something of the length and format of: A3fs9t395dsgSDf3fRsTse349. But not that one! Hardening process should change it for the real deployment of the backend. This particular one A3fs... should not be used even for testing! This is visible in the internet. It's just a dummy value to help randomizing the real one!

    Be context aware! E.g. in the list above the ports are usually changed. And if you use a tunnel, then you target the tunnel port, not the real ports. Ask help! Usually one excel has all the dev time secrets for you.

  8. Application launch

    npm start

    Attention! If it doesn't boot install:

    npm install -g nodemon
  9. Attention! Follow the Frontend repo installation guide as well

How to run nodejs backend using docker-compose

  1. Follow installation steps from 1 to 5

  2. Run this command to launch application

    docker-compose -f docker-compose-be.yaml up -d

How to dockerize the local MariaDB database

  1. Edit the .env file to set your desired database name, root password, secondary user/password combination, and the host machine DB port

  2. Run this command to launch application:

    docker-compose -f docker-compose-db.yaml up -d
  3. Alternatively run from command prompt:

    docker run --detach --name mariadock --env MARIADB_USER=alternate_user --env MARIADB_PASSWORD=alternate_user_psw --env MARIADB_ROOT_PASSWORD=root_psw  mariadb:latest
  4. Access the container terminal:

    docker exec -it mariadock bash
  5. Access the DB directly using mysql terminal command:

    mysql -u root -p
  6. Continue the configuration of the local DB as described in the step by step guide located in Database/Documentation/local_mariadb_windows_installation.md

  7. Reset the database data if needed by removing the created Docker volume:

    docker volume rm db_project_mariadb_volume

    Remove the container and restart it. Note! If the command doesn't work, check the right volume name from the Docker compose script or list all volumes with the following command:

    docker volume ls

    You can also check volumes with Docker Desktop.

How to run mariadb database and nodejs backend using docker-compose

Configuration of the local DB is described in the guide located in Database/Documentation/local_mariadb_windows_installation.md. The docker-compose file covered the process and make the application ready to use.

  1. Follow installation steps from 1 to 5

  2. Edit the docker-compose-dbbe.yaml file to have the right configuration according to your environment (database, username, password, root password)

  3. Run this command to launch database and backend

    docker-compose -f docker-compose-dbbe.yaml up -d
  4. Some useful commands:

    Access mariadb container terminal:

    docker exec -it mariadock sh

    Access mariadb container terminal:

    docker exec -it siba_be_dock sh

    Exit terminal inside container:

    exit

(back to the top)