项目作者: pinceladasdaweb

项目描述 :
Node.js RESTful API boilerplate using Traefik, Docker, Docker Compose, Fastify, JWT and Mongodb
高级语言: JavaScript
项目地址: git://github.com/pinceladasdaweb/docker-fastify-restful-api.git
创建时间: 2021-01-24T15:14:07Z
项目社区:https://github.com/pinceladasdaweb/docker-fastify-restful-api

开源协议:MIT License

下载


Docker Fastify RESTful API

Node.js RESTful API boilerplate using Traefik, Docker, Docker Compose, Fastify, JWT and Mongodb.

Requirements

  1. Node.js >= 16
  2. Docker
  3. Docker compose

Getting started

Install packages using docker:

  1. docker run --rm -it \
  2. -v ${PWD}:/usr/src/app \
  3. -w /usr/src/app \
  4. node:16-alpine npm i

Windows users should switch the PWD variable to your current directory. Alternatively, you can run npm install as follows:

  1. docker-compose run --rm api npm install

Or if you have node installed in your system, install using npm:

  1. npm install

Configuration

  1. Rename the .env.example file to .env and fill variables. The Postgres variables are required for Sonarqube. The SENTRY_DSN variable is not obligatory.

  2. Edit your hosts file with:

    127.0.0.1 fastify.localhost

    127.0.0.1 sonarqube.localhost

Run

In the root of project, run:

  1. docker-compose up

API Request

Endpoint HTTP Method Description
/api/v1 GET Healthcheck
/api/v1/users/register POST Adds a new user
/api/v1/users/auth POST Authenticate user
/api/v1/movies GET List all movies
/api/v1/movies/:id GET Get movie
/api/v1/movies POST Adds a new movie
/api/v1/movies/:id PATCH Update a movie
/api/v1/movies/:id DELETE Delete a movie

Test API locally using curl

  • Healthcheck

Request

  1. curl -i --request GET 'http://fastify.localhost/api/v1'

Response

  1. {
  2. "message": "Fastify API is on fire"
  3. }

Insominia Collection

I exported Insomnia collection/data for so you can test all the endpoints.

Sonarqube dashboard

To access Sonarqube dashboard, simple access in your browser:

  1. http://sonarqube.localhost

Follow the guide to learn more about the settings and how to run Sonar code analysis.

Traefik dashboard

To access Traefik dashboard, simple access in your browser:

  1. http://localhost:8080

Infrastructure model

Infrastructure model

Happy coding!