BackendStack21/fast-gateway

All defined routes return 404

Closed this issue · 4 comments

Describe the bug
Please forgive my ignorance if I've missed something completely obvious here.
I'm just trying to run a very simple gateway based off your basic demo and all of the routes return 404.

My example server.js
'use strict'

const gateway = require('fast-gateway')
const PORT = process.env.PORT || 8080

gateway({
  routes: [{
    prefix: '/public',
    target: 'http://localhost:3000'
    /*
    // applicable in case Swagger Definitions would be supported on downstream service
    docs: {
      name: 'Public Service',
      endpoint: 'swagger.json',
      type: 'swagger'
    }
    */
  }, {
    prefix: '/admin',
    target: 'http://localhost:3001'
  }, {
    // this route definition makes http://localhost:3000 (/public) a default service if other routes prefixes are omitted
    prefix: '/*',
    target: 'http://localhost:3000'
  }]
}).start(PORT).then(server => {
  console.log(`API Gateway listening on ${PORT} port!`)
})

const service1 = require('restana')({})
service1
  .get('/hi', (req, res) => res.send('Hello World!'))
  .get('/hi-chunked', (req, res) => {
    res.write('Hello ')
    res.write('World!')
    res.end()
  })
  .start(3000).then(() => console.log('Public service listening on 3000 port!'))

const service2 = require('restana')({})
service2
  .get('/users', (req, res) => res.send([]))
  .start(3001).then(() => console.log('Admin service listening on 3001 port!'))

I'm using
Node version: 14.15.3
Npm version: 7.5.3
MacOS 11.2

To Reproduce
Copy the server.js file above.
run node server.js
I see the startup output fine

API Gateway listening on 8080 port!
Public service listening on 3000 port!
Admin service listening on 3001 port!

I've checked lsof and the servers are running and listening:
image

I hit /services.json
and I get the routes outputting
image

If I hit any other route on the gateway I get nothing

image
image

If I hit the targets directly eg.
http://localhost:3000/hi or http://localhost:3001/users I get Hello World! and [] respectively.

Expected behavior
I'd expect the defined routes to return the various responses from the targets.

Desktop (please complete the following information):

  • OS: MacOS 11.2
  • Browser chrome & safari tried
  • Version 90

Additional context
Node version: 14.15.3
Npm version: 7.5.3

Hi @raldred, thanks for reaching out. Why are you using pathRegex: ''. Can you try without it?

Regards

Hey @jkyberneees yeh not sure, i think i was just trying stuff, the basic demo has it it for the catch all route.
Even with pathPrefix removed, the only route that works is /services.json

I've updated the example im using with the pathPrefix removed

@jkyberneees What if I want to match my endpoints exactly? For example, I want /v1/users defined in the gateway to forward the request exactly like that to the API that has a route defined the same way v1/users