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

Build-in SNI support request. #88

Closed SaltFish001 closed 1 year ago

SaltFish001 commented 1 year ago

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

jkyberneees commented 1 year ago

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

SaltFish001 commented 1 year ago

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
}]
jkyberneees commented 1 year ago

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

SaltFish001 commented 1 year ago

Thanks!