BackendStack21/fast-gateway

Internal route for health check

maxmartinezc opened this issue ยท 4 comments

Hello,
is it possible to implement an internal router for health check (/ health, / readiness, / liveness) ?

Thank's

My workaround is:

const server = gateway({ middlewares: [ Cors(), bodyParser.json() ], routes: [{ prefix: '/health', methods: ['GET'], hooks: { async onRequest(req, res) { res.send({ status: 'UP' }); return true; } } }] });

Hi @maxmartinezc, excuses for reaching out a bit late. You can simply setup your health check using restana routes. Please see example below:

const service = gateway({
  routes: [{
    prefix: '/service',
    target: 'http://127.0.0.1:3000'
  }]
})

service.get('/health', (req, res) => {
  res.send({
    status: 'OK'
  })
})

service.start(PORT).then(server => {
  console.log(`API Gateway listening on ${PORT} port!`)
})

Your solution also works, but I would take this one instead for performance reasons.

Thanks again for reaching out.

I am doing something similar but I have a global middleware enabled in the gateway obj, it looks like the middleware is getting executed. Is there a way to prevent the middleware to run when we go to http://127.0.0.1:3000/whateverNotMatchingThePrefix. Hope to be clear!

Hi @angherq, thanks for reaching out.
Can you please attach some code snippet that can describe your configuration?

Thanks