Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[api-gateway] inspired by BackendStack21/fast-gateway #32

Open
whatwewant opened this issue Nov 14, 2021 · 1 comment
Open

[api-gateway] inspired by BackendStack21/fast-gateway #32

whatwewant opened this issue Nov 14, 2021 · 1 comment

Comments

@whatwewant
Copy link
Member

Repo

@whatwewant
Copy link
Member Author

State/Config first

{
  // Optional server instance. Any HTTP framework that supports the following signature is compatible:
  // - server[HTTP_METHOD](pattern, [middleware1, middleware2,], handler)
  // 
  // Known compatible frameworks: Restana, Express.js
  // If omitted, restana is used as default HTTP framework
  server, 
  // Optional restana library configuration (https://www.npmjs.com/package/restana#configuration)  
  // Please note that if "server" is provided, this settings are ignored.
  restana: {},
  // Optional global middlewares in the format: (req, res, next) => next() 
  // Default value: []
  middlewares: [],
  // Optional global value for routes "pathRegex". Default value: '/*'
  pathRegex: '/*',
  // Optional global requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
  // Ignored if proxyType = 'lambda'
  timeout: 0,
  // Optional "target" value that overrides the routes "target" config value. Feature intended for testing purposes.
  targetOverride: "https://yourdev.api-gateway.com",
  // Optional "Proxy Factory" implementation, allows the integration of custom proxying strategies.
  // Default value: require('fast-proxy-lite/lib/proxy-factory')
  proxyFactory: ({ proxyType, opts, route }) => {...}

  // HTTP proxy
  routes: [{
    // Optional proxy type definition. Supported values: http, http-legacy, lambda
    // Modules:
    // - http: fast-proxy-lite
    // - http-legacy: fast-proxy
    // - lambda: http-lambda-proxy
    // Default value: http
    proxyType: 'http'
    // Optional proxy library configuration: 
    // - fast-proxy-lite: https://www.npmjs.com/package/fast-proxy-lite#options
    // - fast-proxy: https://www.npmjs.com/package/fast-proxy#options
    // - http-lambda-proxy: https://www.npmjs.com/package/http-lambda-proxy#options
    // Default value: {}
    proxyConfig: {},
    // Optional proxy handler function. Default value: (req, res, url, proxy, proxyOpts) => proxy(req, res, url, proxyOpts)
    proxyHandler: () => {},
    // Optional path matching regex. Default value: '/*'
    // In order to disable the 'pathRegex' at all, you can use an empty string: ''
    pathRegex: '/*',
    // Optional service requests timeout value (given in milliseconds). Default value: '0' (DISABLED)
    // This setting apply only when proxyType = 'http'
    timeout: 0,
    // route prefix
    prefix: '/public',
    // Optional documentation configuration (unrestricted schema)
    docs: {
      name: 'Public Service',
      endpoint: '/api-docs',
      type: 'swagger'
    },
    // Optional "prefix rewrite" before request is forwarded. Default value: ''
    prefixRewrite: '',
    // Optional "url rewrite" hook. If defined, the prefixRewrite setting is ignored. 
    urlRewrite: (req) => req.url,
    // Remote HTTP server URL to forward the request. 
    // If proxyType = 'lambda', the value is the name of the Lambda function, version, or alias.
    target: 'http://localhost:3000',
    // Optional HTTP methods to limit the requests proxy to certain verbs only
    // Supported HTTP methods: ['GET', 'DELETE', 'PATCH', 'POST', 'PUT', 'HEAD', 'OPTIONS', 'TRACE']
    methods: ['GET', 'POST', ...], 
    // Optional route level middlewares. Default value: []
    middlewares: [],
    // Optional proxy lifecycle hooks. Default value: {}
    hooks: {
      async onRequest (req, res) {
      //   // we can optionally reply from here if required
      //   res.end('Hello World!')
      //
      //   // we can optionally update the request query params from here if required
      //   req.query.category = 'js'
      //
      //   return true // truthy value returned will abort the request forwarding
      },
      onResponse (req, res, stream) {  
        // do some post-processing here
        // ...
      }

      // if proxyType= 'http', other options allowed https://www.npmjs.com/package/fast-proxy-lite#opts
    }
  }]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant