Killer Api.
Nest framework is used in this project.
Install global Nest CLI if not already done:
$ npm install -g @nestjs/cli
Then install dependencies:
$ yarn
Then create a local .env file:
$ cp .env.dist .env
This .env file is git ignored, fill it with your real local secrets.
This project use a PostgreSQL DB and Mercure on a caddy server. If you prefer, you can run them inside containers with
$ docker-compose up -d
Then run knex migrations (install knex CLI before perform these actions) :
$ knex migrate:latest
To load fixtures from seeds files :
$ knex seed:run
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Knex is a SQL query builder.
You can download is CLI to perform some actions:
$ npm install knex -g
You can create migrations files that you have to fill:
$ knex migrate:make migration_name
Run migrations in database:
$ knex migrate:latest
Create seed file:
$ knex seed:make seed_name
See more on Knex
Start by downloading mercure release archive on Mercure Github.
Then unzip it in a directory of your choice.
Then you can launch a mercure instance (running in a caddy server) with the follozing command, using the mercure executable you've just extracted :
$ MERCURE_PUBLISHER_JWT_KEY='killer-mercure-publisher' \
MERCURE_SUBSCRIBER_JWT_KEY='killer-mercure-subscriber' \
SERVER_NAME=:5000 \
./mercure run -config Caddyfile.dev
It automatically runs mercure on port 5000. If you get an error such as forbidden
on this port, just switch the port used to a free port that you are allowed to use.
Now that Mercure is running, you can subscribe to it.
Subscriptions to Mercure are performed with eventSource, and detailed in this article.
Nest is MIT licensed.