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

Supporting hostnames #52

Closed jkyberneees closed 4 years ago

jkyberneees commented 4 years ago
'use strict'

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

const hostnames2prefix = [{
  prefix: '/public',
  hostname: 'nodejs.org'
}]
const hostnamesHook = require('./../lib/hostnames-hook')(hostnames2prefix)

const app = restana()
const server = http.createServer((req, res) => {
  hostnamesHook(req, res, () => {
    return app(req, res)
  })
})

gateway({
  server: app,
  middlewares: [
  ],

  routes: [{
    prefix: '/public',
    target: 'http://localhost:3000'
  }]
})

server.listen(PORT)

const origin = require('restana')({})
origin
  .get('/hi', (req, res) => res.send('Hello World!'))
  .start(3000)
jkyberneees commented 4 years ago

Issue ref: https://github.com/jkyberneees/fast-gateway/issues/51