Apiko 2021 spring courses API

API - https://apiko-2021-spring-course-api.herokuapp.com/

API Docs - https://apiko-2021-spring-course-api.herokuapp.com/documentation

Installation

Clone repository and install project dependencies

git clone https://github.com/apiko-dev/apiko-2021-spring-course-api
cd apiko-2021-spring-course-api
npm i

Environment variables

Add your .env file with required environment variables e.g.

DATABASE_URL=postgres://apiko:apiko@db:5432/apiko
# For deployed db - `TRUE`, for local db - `FALSE`
PGSSL=FALSE
# For deployed db - `no-verify`, for local db - `FALSE`
PGSSLMODE=FALSE

Docker

Download Docker Desktop for your system

Scripts

Build docker images:

npm run docker:build

Run docker app:

npm run docker:run

Run db migrations:

npm run docker:migrate:update
npm run docker:migrate:rollback
npm run docker:migrate:rollback:all

Connect to db container

If you want to connect to database from root machine, you can connect to database with a name apiko on localhost:5452 with username/password apiko - postgres://apiko:apiko@localhost:5452/apiko.

To connect to database within docker network, connect to db:5432.

Connect to api container

If you want to connect to api from root machine, you can connect to localhost:8090.

To connect to api within docker network, connect to api:8090.

SQL syntax highlight in js files.

Use VS Code Extension for Syntax highlighting for code like:

const query = sql`SELECT * FROM users`;

Deploy on Heroku

Create free Heroku account and create new app from dashboard.

Download, install and login into Heroku CLI.

Set and add the following buildpacks using heroku cli:

$ heroku buildpacks:set heroku/nodejs -a YOUR_HEROKU_PROJECT_NAME
$ heroku buildpacks:add heroku/jvm -a YOUR_HEROKU_PROJECT_NAME

Install Heroku Postgres and provision it to your heroku app.

Config Vars

Open your heroku app Settings from dashboard and set following Config Vars from Heroku Postgres credentials:

DATABASE_URL=
PGSSL=TRUE
PGSSLMODE=no-verify

Also set the following Config Vars:

HOST=YOUR_HEROKU_PROJECT_NAME.herokuapp.com
SECRET1=
SECRET2=

Add the heroku remote to the git repository

heroku git:remote -a YOUR_PROJECT_HEROKU_GIT_URL

Deploy your changes:

git push heroku master

or

git push heroku local_branch_name:master