@tribeca/api-gateway

simple api gateway library

Usage no npm install needed!

<script type="module">
  import tribecaApiGateway from 'https://cdn.skypack.dev/@tribeca/api-gateway';
</script>

README

api-gateway

Api Gateway library package

Npm Version Actions Status CodeFactor codecov Dependabot Status

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.