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-usBasically, 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
}nameService's name (Just for debug and log purpose)hostThe host that is service runningportThe port that is service runningprefixPublic service prefixhttpsService is running under https? (boolean)
The name of service. It would be used for logs and error handlers.
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/urlThe 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.
Just a boolean for the service protocol, if true, the request will be done over HTTPS protocol. Defaults to false.
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.
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-uspt-br
Help us make the Gateway API global: write a translation and make a pull request.
- 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.