Web services for politica dilemma.
- nodejs (>=16.13.x)
- npm (>=8.1.0)
- docker (>=20)
- docker compose (>=1)
-
Set environments variables
Copy the.env-example
file and name it.env
, then set the appropriated values. For details, see Environment variables section. -
Inizialize database
Launch thenpm run init-stack
script for initialize the postgres and redis instance. -
Start server
Start the server withnpm start
(development) ornpm run dev
(production) scripts.
Bold env must be requred.
Name | Default | Description |
---|---|---|
NODE_ENV | Nodejs environment | |
SERVER_ADDRESS | 127.0.0.1 | Server address |
SERVER_PORT | 3000 | Server port |
API_DOMAIN | Production, staging or dev domain | |
LOG_LEVEL | info | Pino.js default log level |
SESSIONS_LIMIT | 4 | Session number limit |
PG_HOST | Postgres host | |
PG_PORT | Postgres port | |
PG_DB | Postgres database | |
PG_USER | Postgres user | |
PG_PW | Postgres password | |
SENATO_URL_DATA | Senato portal url | |
REDIS_HOST | Redis host | |
REDIS_PORT | Redis port | |
SECRET | Secret string (used to sign the cookie) | |
SESSION_TTL | 1800 (30 minutes) | Session TTL (in seconds) |
COOKIE_TTL | 15552000 (6 months) | Cookie max age (in seconds) |
RESET_LINK_TTL | 7200 (2 hours) | Reset link TTL (in seconds) |
ENABLE_BODY_LOG | false | Enable request body logging |
ENABLE_API_AUDIT | false | Enable api audit persistence |
ENABLE_LOG_ACTIVITY | false | Enable log activity persistence |
AWS_REGION | AWS REGION | |
AWS_ACCESS_KEY_ID | AWS access key id | |
AWS_SECRET_ACCESS_KEY | AWS access key key | |
SENDER_EMAIL | Email address used to send email from | |
STATIC_FILES_DEST | Static files destination full path | |
SENTRY_DSN | Sentry dsn | |
SENDGRID_API_KEY | Sendgrid api key |
PS: If you have difficulties to compiling the env file, ask the backend guy!
If the server is launched with the npm run dev
script (development mode), the API documentation can be consulted at http://{SERVER_ADDRESS}:{SERVER_PORT}/doc
.
The system uses a cookie-based authentication system.
To authenticate the user, the auth/login
API must be consumed with the right inputs. When this is done, the API returns a secure cookie to the client, and that's all.
The cookie will be automatically added in the requeset by the user agent, since it can't be accessed by the client application due to security reasons.
To remove the user authentication from the system, call the auth/logout
API.
When the postgres container is created for the first time, some data is initialized.
For example, there are available some users, useful to log into the system.
These are it's credentials
[email protected]
: Password1[email protected]
: Password1[email protected]
: Password1
NB: obviously this data is only available in the development environment.
To launch the test suite, run the npm run test
script.
Userful commands to directly access to the containers:
- postgres -->
docker container exec -it postgres-pd /bin/bash
- postgres (psql) -->
docker container exec -it postgres-pd psql -U postgres
- redis -->
docker container exec -it redis-pd /bin/bash
- redis (redis-cli) -->
docker container exec -it redis-pd redis-cli