BackendStack21/fast-gateway

Route subpaths

Closed this issue · 7 comments

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

Could you please describe your issue in more details?

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?

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

Thanks

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?

Just do:

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

Doesn't work

I'm sorry, it does work

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

Thanks for the info