Skip to content

poliedros/api-gateway

Repository files navigation

api-gateway

Github Actions Coverage Status

Description

Api gateway is the facade api for projects

Authentication

To keep a route safe, use JwtAuthGuard

@UseGuards(JwtAuthGuard)
@Get('profile')
getProfile(@Request() req) {
  return req.user;
}

Authorization

Add your role to role.enums.ts

export enum Role {
  Admin = 'admin',
  Other = 'other',
}

Now, you can use it on your controllers

@UseGuards(JwtAuthGuard, RolesGuard)
@Roles(Role.Admin)
@Get('example')
get(@Request() req) {
  return ['Hello world'];
}

Interceptors

Timeout

Timeout interceptor is global and used to timeout a requisition if it takes more than 10 seconds.

app.useGlobalInterceptors(new TimeoutInterceptor());

To change this time, jump to timeout.interceptor.ts and change this lin:

return next.handle().pipe(timeout(10000));

Health

Health module is used to check if the API itself is up and running and to check other services.

Users

Module to keep users' data saved. It can be used with whatever database the project requires.

Architecture

Solution architecture

Installation

$ yarn install

Running the app

# development
$ yarn start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Test

# unit tests
$ yarn test

# e2e tests
$ yarn test:e2e

# test coverage
$ yarn test:cov