- Quickstart (with Docker)
- Quickstart (without Docker)
- Environment variables
- Database Migrations
- Working with translations
- Deployment
We recommend using docker and docker-compose to make the setup easier.
dockeranddocker-compose: see https://docs.docker.com/install/overview/
The API needs to be linked to a Postgres database in order to operate correctly. One will be automatically created for you from our
docker-composeconfiguration.
To start the local development server, run the following:
docker-compose up apiThe server will be started and listen on your local port 5000. You will be able to access it throught http://localhost:5000/.
To stop all running containers, run:
docker-compose downYou can start the database independently with the following command:
docker-compose up db
# You can also start it in the background with the `-d` option
docker-compose up -d dbIf you want to clear all existing data, you can remove the local volumes:
docker-compose down -vAnd then run docker-compose up api again.
To start a shell inside the container, run the following:
docker-compose run --rm api shYou can then run commands like npm install ... from the container.
The
--rmoption is used to remove the container after its execution and not have mulitple existing instances
// TODO
| Name | Description | Required | Default value |
|---|---|---|---|
PORT |
The port on which the API will listen | true |
5000 |
JWT_PRIVATE_KEY |
The secret key used by JsonWebTokens | true |
undefined |
You have 2 ways of configuring the database connection.
You can use DATABASE_URL:
| Name | Description | Required | Default value |
|---|---|---|---|
DATABASE_URL |
The database url | true |
undefined |
Be sure to have the required environment variables defined before running the commands introduced in this section. See Database Environment.
You should also make sure that your database is running.
A typeorm script is defined in the package.json to help you interact with our ORM.
To apply all pending migrations and update your database schema, run the following:
npm run typeorm -- migration:runThe
--here is used to make sure that the next passed parameters or arguments are not interpreted by npm and forwarded as is to typeorm's cli. This is especialy useful in the next command.
To create a new migration from the model entities, run the following command:
npm run typeorm -- migration:generate -n NameOfTheMigrationIt will create a new migration file in sources/models/migrations named
$TIMESTAMP-NameOfTheMigration.
Be sure to apply all pending migrations before creating a new one or the generated migration will be incorrect.
We use i18next and its koa module koa-i18next to handle localization.
See more about i18next here.
Translation files can be found in sources/assets/locales. Each folder corresponds to a locale and contains a translation.json.
Controllers will receive locale information in their Koa.Context argument.
This context will then contain a function t that can be used like this:
function controller = (ctx: Koa.BaseContext): Promise<void> => {
ctx.status = 200;
ctx.body = {
/* Will return the value associated with the key in the `translation.json` file */
message: ctx.t("translation.key")
};
}When dealing with translation keys, prevent editing the translation.json file yourself. Instead use the script i18next:extract.
It will read the whole code base looking for calls to t(...) and generate new entries
for the keys that are not listed in the translation file.
npm run i18next:extract// TODO