Skip to content

Instantly share code, notes, and snippets.

@wesleymonaro
Created November 20, 2018 22:43
Show Gist options
  • Save wesleymonaro/655108bfe67ef6f9cfc2c5444c356d7b to your computer and use it in GitHub Desktop.
Save wesleymonaro/655108bfe67ef6f9cfc2c5444c356d7b to your computer and use it in GitHub Desktop.
const express = require('express');
const httpProxy = require('express-http-proxy');
const app = express();
const port = 3000;
const {
USERS_API_URL,
PRODUCTS_API_URL,
} = require('./URLs');
const userServiceProxy = httpProxy(USERS_API_URL);
const productsServiceProxy = httpProxy(PRODUCTS_API_URL);
app.get('/', (req, res) => res.send('Hello Gateway API'));
app.get('/users', (req, res, next) => userServiceProxy(req, res, next));
app.get('/products', (req, res, next) => productsServiceProxy(req, res, next));
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment