Skip to content

danielbonifacio/gateway-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

diagram

Gateway API

Free Node.js Gateway API model.

Before start, make sure you have an .env file with an SECRET key placed in your project's root.

SECRET=YOUR_SECRET_TOKEN
PORT=80
LANG=en-us

Services Mapping

Basically, to add or remove a service you'll need to change the services.map.js file.

It contains an array of Service Objects.

There's some props that'll need to pass to the Gateway API, so then it can recognize your service:

const service = {
  name: 'Posts',
  prefix: 'posts',
  host: '127.0.0.1',
  port: '4567',
  https: false
}
  • name Service's name (Just for debug and log purpose)
  • host The host that is service running
  • port The port that is service running
  • prefix Public service prefix
  • https Service is running under https? (boolean)

Name

The name of service. It would be used for logs and error handlers.

Prefix

The public prefix for the service, on gateway.

In Posts service example above, the public URL will be:

${api}/posts/some/rest/url
       ^^^^^

Note that prefix will not be sent to the service. So, on the previous URL example, the request sent to service will be:

${service}/some/rest/url

Host & Port

The service's host and port.

If your service is accessible via 127.0.0.1:3000 the host and port will be 127.0.0.1 and 3000 respectively.

HTTPS

Just a boolean for the service protocol, if true, the request will be done over HTTPS protocol. Defaults to false.

Auth Middleware

By default, all requests needs to pass on the Auth method.

You cannot get out of it. So if you need "token free" public link, make sure you've been added a condition in middlewares/auth.js.

If you want to add another middleware, you can do it in helpers/routerRegister.js file.

Translations

By default, the Gateway sets en-us as default language. You can change it overwritting the process.env.API_LANG to the JSON translation file that you want.

Current available translations:

  • en-us
  • pt-br

Help us make the Gateway API global: write a translation and make a pull request.

Packages and Credits

  • Daniel Bonifacio @danielbonifacio - Created the repo and maintain all this code
  • Express - Microframework
  • Nodemon - Livereload server
  • Axios - HTTP request library

If you find a bug or think something could be better, please, create a issue or a pull request.

About

Gateway API Open Source

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published