Both servers share the User
model, so a monorepo was ideal at the moment. However, an ideal configuration would be three packages:
trador-models
: an NPM package containing all the models with types. Installed from source as a dependency.auth-server
: contains all Auth controllers and services.api-server
: contains all API controllers and services.
Run
$ npm run build
Create a copy of .env.sample
and rename it to .env
$ cp .env.sample .env
All can be left as they are except for MONGO_URI
.
Both servers can be deployed using PM2 in a single command. The configurations are in ecosystem.config.js
. In the command line, type:
$ pm2 start ecosystem.config.js
Each server is configured to have two instances, which is more than enough for a small-scale application.
Logs can be traced using by running:
$ pm2 logs
You can setup an Nginx proxy like this:
server {
listen 80;
listen [::]:80;
server_name auth.app.io;
location / {
proxy_pass http://127.0.0.1:4001;
}
}
server {
listen 80;
listen [::]:80;
server_name api.app.io;
location / {
proxy_pass http://127.0.0.1:4002;
}
}