Coder Social home page Coder Social logo

ezy / express-api-gateway Goto Github PK

View Code? Open in Web Editor NEW
8.0 3.0 2.0 125 KB

⛩️ A simple lightweight API gateway that will run in a docker container, then authenticate and proxy http requests

License: MIT License

JavaScript 95.99% Dockerfile 4.01%
node nodejs node-js express expressjs express-js api-gateway api gateway-api gateway gateway-microservice gateway-node gateway-skeleton jwt auth jwt-auth proxy-server docker docker-compose

express-api-gateway's Introduction

⛩️ Node Express Docker API Gateway

A simple lightweight API gateway that will run in a docker container, authenticate using a JWT strategy and then conditionally auto-generate routes from config or proxy all req.url strings to the specified proxy URL. Great for micro-service architecture and abstracting your security layer away from your primary app if required.

Installation

You'll need docker if you don't already ahve it installed. Containerize all the things!

Adjust the ENV vars in .env.development to your liking and adjust config.js to include setting your hostUrl then:

# clone it
git clone [email protected]:ezy/express-api-gateway.git
cd express-api-gateway


# Build and start your server
docker-compose up --build

API will be available at localhost:<PORT> for http requests.

API Endpoints

Specify your endpoints in config.js under the routes object using the correct request method object (get,post,put,delete). Routes will be generated at runtime from this list using the following configuration:

  • host: { string } over-rides hostUrl to specify proxy target host,
  • path: { string } the target path for the req and res,
  • auth: { boolean } set to true to require JWT authentication for the endpoint

Wildcard proxy

Set proxyAll: true in config to proxy all requests to config.hostUrl. The Authentication Bearer header JWT is turned on by default for proxyAll.

  • /*: (JWT secure) wildcard proxy sends url.req to specified config.hostUrl.

Authentication

A basic JWT token endpoint is available unconfigured at:

  • /oauth/token POST: uses req.body { "userId": "ezy", "password": "Secure" } to return a valid JWT token

HTTP / HTTPS

App is configured for both http and https and runs http out of the box. To enable https generate (or provide) your https certs - privateKey.pem, certificate.pem, authority.pem (optional) - in the root directory, and set config.protocol: 'https'.

Postman client

Import the postman file located at ./scalpelway.postman_collection.json to test the endpoints.

License

MIT

express-api-gateway's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.