@tribeca/api-gateway
v1.2.9
Published
simple api gateway library
Downloads
3
Readme
api-gateway
Api Gateway library package
A simple api gateway built on the top of expressJs.
Installation
$ npm install @tribeca/api-gateway --save
Example
const apiGateway = require("@tribeca/api-gateway");
const corsMiddleware = require("./cors-middleware");
const app = apiGateway();
app.registerMiddleware("cors", corsMiddleware);
const listen = app.initialize({
mappingFilePath: "./mapping.json"
});
const port = process.PORT || 3000;
listen(port, function() {
console.log(`Server listening at port ${port}`);
});
Where mapping.json is
{
"version": 1,
"headers": {
"X-Api-Gateway": "api-gateway"
},
"middlewares": ["cors"],
"services": [
{
"name": "test",
"protocol": "http",
"host": "127.0.0.1",
"port": "3001",
"basePath": "/subpath",
"middlewares": [],
"mappings": [
{
"path": "/test",
"method": "GET",
"middlewares": []
}
]
}
]
}
License
Licensed under MIT.