Skip to content

Latest commit

 

History

History
172 lines (123 loc) · 3.81 KB

README.md

File metadata and controls

172 lines (123 loc) · 3.81 KB

Toiminnansuunnittelu [backend]

Tosu app backend made with Node.js

Build Status

Getting Started

Prerequisites

node.js

Installing

  1. Clone the repository
    git clone [email protected]:partio-scout/tosu-backend-node.git
  2. Install npm packages
    npm install
  3. Add .env file to project root
NODE_ENV=development
HOST_URL=
SAML_METADATA_URL=

DB_HOST=localhost
DB_USERNAME=postgres
DB_PASSWORD=

DB_NAME_DEV=tosudb
DB_NAME_TEST=tosudb_test
DB_NAME_PROD=tosudb_prod

SECRET_KEY=superSecretKeyABC
  • NODE_ENV defines the type of environment (production | development | test) (development by default)
  • SECRET_KEY is used for cookies.
  • HOST_URL is used for SAML routes (can be left undefined for local development).
  • SAML_METADATA_URL is used for fetching the SAML metadata for the IdP.
  1. Install postgreSQL (guide)
  2. Configure database credentials in .env if necessary
  3. Create local development database npx sequelize db:create

NOTE: If the above command doesn't work create the database manually

  1. Access SQL prompt using one of the following
$ psql
$ psql -u postgres
$ sudo -i -u postgres psql
  1. Create databases
-- For development
CREATE DATABASE tosudb;

-- For running tests
CREATE DATABASE tosudb_test;
  1. Exit SQL prompt: \q or exit
  1. Migrate models to the database
    npx sequelize db:migrate

    To undo migrations
    npx sequelize db:migrate:undo:all

  2. Start the server (2 options)

    • Normal mode: npm start
    • Hot reloading: npm run watch

Running tests

  • Run all tests npm test
  • Run single test class npm test activities

Code coverage is generated when tests are run.
A report is printed to the console and an html report generated to /coverage.

Deployment

  1. Get the unencrypted ssh key tosu_node.pem
  2. SSH to the server instance:
$ chmod 600 tosu_node.pem
$ ssh-add tosu_node.pem
$ ssh [email protected]
  1. Install node:
$ curl -sL https://deb.nodesource.com/setup_11.x | sudo -E bash -
$ sudo apt -y install nodejs
  1. Clone the repo:
$ git clone [email protected]:partio-scout/tosu-backend-node.git
  1. Add .env file to project root
NODE_ENV=production
HOST_URL=https://suunnittelu.beta.partio-ohjelma.fi
SAML_METADATA_URL=https://partioid-test.partio.fi/simplesaml/saml2/idp/metadata.php

DB_HOST=localhost
DB_USERNAME=postgres
DB_PASSWORD=(password for the database)

DB_NAME_DEV=tosudb
DB_NAME_TEST=tosudb_test
DB_NAME_PROD=tosudb_prod

SECRET_KEY=(generate some secret key)
  1. Install PM2, a process manager for Node.js applications:
$ sudo npm install pm2@latest -g
  1. Start node process:
$ cd ~/tosu-backend-node
$ npm install
$ pm2 start index.js
  1. Install postgreSQL (guide)

  2. Install NGINX, Reverse proxy and copy nginx.conf file:

$ sudo apt -y install nginx
$ sudo cp /home/ubuntu/tosu-backend-node/nginx.conf /etc/nginx/sites-available/default
  1. Restart nginx:
sudo systemctl restart nginx

Resources

Documentation

TODO: Add documentation

Some documentation can be found in the doc folder.

Backlogs

Product backlog (Trello)
Fall 2018 product & sprint backlog

License

This project is licensed under the MIT License - see the LICENSE file for details.