1.0.0 • Published 3 years ago
alerts-controller v1.0.0
node_service_template
Prerequisites
- create a database
- create an ecs service registry for production / staging / dev + taskDefinition
Setup
- Find and Replace all \${APP_NAME} placeholder with you new service name!
Now we can start setup out new service:
Database
- under config/database.json replace {{%DB_USER%}}, {{%DB_PASS%}}, {{%DB_PORT%}}, {{%DB_DIALECT%}}. make sure the correct dialect, database and port are properly configured (usualy posgres w 5432 / mysql w 3306)
Migrate your first table (Optional)
- change
table_name
in database/migrations and src/models. - replace {{%SystemSettingsRecords%}} with system settings or empty array ([]).
Create your first mode
- change the class name FirstTable
- add relevant fields
make sure you also change the relevant interface name IFirstTable
make sure the model is imported to models/index.ts and exported out.
- correlate the first model, by changing models/first_table.model.ts and interfaces/models.interface.ts
- to create the DB schema and first table, invoke npm run db:prepare:XXX (where XXX is development, staging or production)
- make sure ecs app names are set properly under package.json, docker, buildspec.yml and bin/docker_push.sh.
Sentry
- Create new project with \${APP_NAME}
*
^^ DELETE ABOVE INSTRUCTIONS AFTER SETUP COMPLETES
LT readme template
How to install \$APP_NAME repo
First ensure you have these packages pre-installed on your computer:
- Postgres
you can install both through brew (mac) using the command
brew install postgresql
To run them as a service just call
brew services start postgresql
Setup DB
After installing postgresql
you'll need to run the next commands:
psql postgres
to enter the shell
Then
create database cycle_tagging_service;
CREATE ROLE ctsdbroot WITH LOGIN ENCRYPTED PASSWORD $DB_PASSWORD;
GRANT ALL ON DATABASE cycle_tagging_service TO ctsdbroot;
generate the DB and Schema
npm run db:migrate
Setup the test DB
psql postgres
to enter the shell
Then
create database cycle_tagging_service_test;
GRANT ALL ON DATABASE cycle_tagging_service_test TO postgres;
The run
NODE_ENV=tet npm run db:migrate
Install the service's dependencies
- Make sure you on LTS version or above (10)
- You could use version manager such as
n
ornvm
nvm use
- You could use version manager such as
- Install dependencies simply by using the command
npm install
Authorization
- generate a new jwt secret with:
openssl rand 256 | base64
- to create an access toekn use jwt.sign(). see examples at https://www.npmjs.com/package/jsonwebtoken
- default access token is expected in the header as a Bearer token, but this can be changed in authorization.middleware to be a query string param as well.
Running the service
- Locally simply run postgres and then call
npm start
1.0.0
3 years ago