hseoy / the-beauty-of-science-api

Discuss the beauty of science (Under development) - gwahangmi v2(or the beauty of science v1)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Banner

This is an Express REST API service for The Beauty of Science.

Deployed by Heroku : Click!

Table of content


Technologies

⬆ Back to Top


API Spec

You can read api specification below :

⬆ Back to Top


Setting up a project

  1. Download the source code using git
git clnoe https://github.com/hseoy/the-beauty-of-science-api.git
  1. 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
  1. 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
  1. install the packages through yarn
yarn install

⬆ Back to Top


Environment variables

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.

Common environment variables

  • NODE_ENV : development or production (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)

Development environment variables

  • 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

Production environment variables

  • DATABASE_URL : Set by Heroku Postgres

  • REDIS_TLS_URL : Set by Heroku Redis

  • REDIS_URL : Set by Heroku Redis

⬆ Back to Top


Yarn custom commands

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.

⬆ Back to Top


Test and coverage

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

⬆ Back to Top


Deployment

We deploy using heroku.

  1. Create deploy branch for deployment.
$ git checkout --orphan deploy
$ git reset --hard
$ git commit --allow-empty -m "Init deploy branch"
$ git checkout main
  1. Then, mount the branch as a subdirectory using git worktree:
$ git worktree add dist deploy
  1. Run yarn predeploy
$ yarn predeploy
  1. Deploy to heroku after commit
$ cd dist
$ git add .
$ git commit -s -m "Update"
$ git push heroku deploy:main

⬆ Back to Top


LICENSE

MIT © hseoy

About

Discuss the beauty of science (Under development) - gwahangmi v2(or the beauty of science v1)

License:MIT License


Languages

Language:JavaScript 99.7%Language:Shell 0.3%