BackendStack21/fast-gateway

Build-in SNI support request.

Closed this issue · 4 comments

I want to use different base Domain in my Api-gateway.

Hi @SaltFish001, first of all, thanks for supporting this project!
Not sure if I understood correctly, but I try my best.

fast-gateway core functionality is built on top of prefix routing, which guarantees higher performance. In order to support multiple domain names to target underlying services, I would recommend you to create a translation table. Please see the documentation link below:

Summary:

// binding hostnames to prefixes
const hostnames2prefix = [{
  prefix: '/api',
  hostname: 'api.company.tld'
}]
// instantiate hostnames hook, this will prefix request urls according to data in hostnames2prefix
const hostnamesHook = require('fast-gateway/lib/hostnames-hook')(hostnames2prefix)

// separately instantiate and configure restana application
const app = restana()
const server = http.createServer((req, res) => {
  hostnamesHook(req, res, () => {
    return app(req, res)
  })
})

// gateway configuration
gateway({
  server: app, // injecting existing restana application
  routes: [{
    prefix: '/api',
    target: 'http://localhost:3000'
  }]
})

server.listen(8080)

Best Regards,
Rolando

Hi @SaltFish001, first of all, thanks for supporting this project! Not sure if I understood correctly, but I try my best.

fast-gateway core functionality is built on top of prefix routing, which guarantees higher performance. In order to support multiple domain names to target underlying services, I would recommend you to create a translation table. Please see the documentation link below:

Summary:

// binding hostnames to prefixes
const hostnames2prefix = [{
  prefix: '/api',
  hostname: 'api.company.tld'
}]
// instantiate hostnames hook, this will prefix request urls according to data in hostnames2prefix
const hostnamesHook = require('fast-gateway/lib/hostnames-hook')(hostnames2prefix)

// separately instantiate and configure restana application
const app = restana()
const server = http.createServer((req, res) => {
  hostnamesHook(req, res, () => {
    return app(req, res)
  })
})

// gateway configuration
gateway({
  server: app, // injecting existing restana application
  routes: [{
    prefix: '/api',
    target: 'http://localhost:3000'
  }]
})

server.listen(8080)

Best Regards, Rolando

Thanks reply! But that's not what I mean.
I mean use different certs with different Doamin

const hostnames2prefix = [{
  prefix: '/api',
  hostname: 'api.company.tld',
  cert: Buffer | pathString
  key: Buffer | pathString
  ca?: Buffer | pathString
}]

Hi @SaltFish001, thanks for clarifying. As previously noted, fast-gateway uses de Node.js Http Server interface, so the same principles apply.

The following discussion will provide you few alternatives:

https://stackoverflow.com/questions/42522805/multiple-ssl-certificates-and-http-2-with-express-js

Overall, I would suggest you to offload SSL termination to Nginx, Caddy or Kubernetes Ingress controllers. Of course, it would depend of your infrastructure conditions.

Best Regards

Thanks!