This is an Express REST API service for The Beauty of Science
.
Deployed by Heroku : Click!
- Technologies
- API Spec
- Setting up a project
- Environment variables
- Yarn custom commands
- Test and coverage
- Deployment
- LICENSE
You can read api specification below :
- Download the source code using git
git clnoe https://github.com/hseoy/the-beauty-of-science-api.git
- We use PostgreSQL and Redis to store the data. Please install it.
# Create the file repository configuration:
$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
# Import the repository signing key:
$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
# Update the package lists:
$ sudo apt-get update
# Install the latest version of PostgreSQL.
$ sudo apt-get -y install postgresql
# Install redis server
$ sudo apt-get install redis-server
# start redis server
$ redis-server --daemonize yes
- Set up the database.
# Create the_beauty_of_science postgres database
$ createdb the_beauty_of_science
# Create tables for this project
$ chmod +x create_tables.sh
$ ./create_tables.sh
# Check
$ psql the_beauty_of_science
$ the_beauty_of_science=# \d
- install the packages through yarn
yarn install
Environment variables can be set by writing in the .env
file.
.env.dev
: Environment variables used in development
.env
: Environment variables used for production. This is not included in version control.
-
NODE_ENV :
development
orproduction
(default :development
) -
PORT : server port number (default :
5000
) -
JWT_ALGORITHM : algorithm for JWT. ex -
HS256
,RS256
, ... -
JWT_SECRET : secret string for JWT
-
JWT_EXPIRE_ACCESS :the expiration time of the access token (Hour)
-
JWT_EXPIRE_REFRESH : the expiration time of the refresh token (Hour)
-
REDIS_HOST : ip address of the redis server running. ex -
127.0.0.1
-
REDIS_PORT : port number of the redis server running. ex -
6379
-
DB_HOST : postgres ip address. ex -
127.0.0.1
-
DB_USERNAME : database user name.
-
DB_PASSWORD : database user password.
-
DB_NAME : database name. ex -
the_beauty_of_science
-
DATABASE_URL : Set by
Heroku Postgres
-
REDIS_TLS_URL : Set by
Heroku Redis
-
REDIS_URL : Set by
Heroku Redis
We defined some commands for convenience:
-
yarn start
: Run the server in production mode -
yarn start:dev
: Run the server in development mode -
yarn lint
: Run eslint -
yarn lint:fix
: Run Eslint to fix the errors -
yarn build
: Build code -
yarn predeploy
: Prepare for deployment -
yarn test
: Run test code -
yarn coverage
: Run test code and generates a coverage report.
You can execute the test code using the commands below
$ yarn test
$ yarn coverage
The command yarn coverage
generates a coverage report, which can be found here
We deploy using heroku.
- Create deploy branch for deployment.
$ git checkout --orphan deploy
$ git reset --hard
$ git commit --allow-empty -m "Init deploy branch"
$ git checkout main
- Then, mount the branch as a subdirectory using git worktree:
$ git worktree add dist deploy
- Run
yarn predeploy
$ yarn predeploy
- Deploy to heroku after commit
$ cd dist
$ git add .
$ git commit -s -m "Update"
$ git push heroku deploy:main
MIT © hseoy