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 34 forks source link

Route subpaths #16

Closed nandanugg closed 4 years ago

nandanugg commented 4 years ago
gateway({
routes: [
    // 404, is this the expected behaviour?
    {
      prefix: '/variable/country',
      target: process.env.USER_SERVICE_HOST + "/variable"
    },
]
})
jkyberneees commented 4 years ago

Could you please describe your issue in more details?

nandanugg commented 4 years ago

Let's say I have restana server installed and serve something inside it's path

const server = require('restana')();
server.get("/inside/something", (req, res) => {
  res.send("Hello world!")
})
server.start(3001);

And I try to serve it's content via gateway, but also inside a deep path

const gateway = require('fast-gateway');
const gatewayService = gateway({
  routes: [{
    prefix: '/outside/something',
    target: 'http://localhost:3001/inside/something'
  }]
});
gatewayService.start(8080)

If I try to get http://localhost:8080/outside/something it gives 404 Is this the expected behavior?

jkyberneees commented 4 years ago

Hi @nandanugg, please override the default pathRegex value. As described: https://github.com/jkyberneees/fast-gateway/blob/master/test/config.js#L13

Thanks

nandanugg commented 4 years ago

Hmm, I not quite understand what pathRegex is, I already try these

    {
      prefix: '/outside',
      pathRegex: '/something',
      target: 'http://localhost:3001/inside/something'
    },
    {
      prefix: '/something',
      pathRegex: '/outside',
      target: 'http://localhost:3001/inside/something'
    },
    {
      prefix: '/outside/something',
      pathRegex: '/something',
      target: 'http://localhost:3001/inside'
    },
    {
      prefix: '/outside/something',
      pathRegex: '/inside/something',
      target: 'http://localhost:3001'
    },

None of them work, what does it do actually?

As I read in your documentation Optional path matching regex. Default value: '/*' What path? Is it the prefix path or target path?

jkyberneees commented 4 years ago

Just do:

   {
      prefix: '/outside/something',
      pathRegex: '',
      target: 'http://localhost:3001'
   }
nandanugg commented 4 years ago

Doesn't work

nandanugg commented 4 years ago

I'm sorry, it does work

    {
      prefix: '/outside/something',
      pathRegex: '',
      target: 'http://localhost:3001/inside/something'
    },

Thanks for the info