BackendStack21 / fast-gateway

Fast-gateway is an easy to use Node.js API gateway framework built to handle large scale API traffic with great performance and scalability. Written with JavaScript, it is a framework for the masses!
MIT License
311 stars 35 forks source link

Adding url rewrite hook #61

Closed jkyberneees closed 3 years ago

jkyberneees commented 3 years ago
'use strict'

const gateway = require('../index')
const PORT = process.env.PORT || 8080

gateway({
  routes: [{
    pathRegex: '',
    prefix: '/customers/:customerId',
    target: 'http://localhost:3000',
    urlRewrite: ({ params: { customerId } }) => `/users/${customerId}`
  }]
}).start(PORT).then(server => {
  console.log(`API Gateway listening on ${PORT} port!`)
})

const service = require('restana')({})
service
  .get('/users/:id', (req, res) => res.send('Hello ' + req.params.id))
  .start(3000).then(() => console.log('Service listening on 3000 port!'))