Skip to content

Adding RegExp support in route prefix #95

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

Merged
merged 6 commits into from
Sep 28, 2024

Conversation

jkyberneees
Copy link
Collaborator

@jkyberneees jkyberneees commented Sep 28, 2024

Fixes: #94

Usage example:

gateway({
  server: express(),

  middlewares: [require('cors')(), require('helmet')()],

  routes: [
    {
      prefix: new RegExp('/public/.*'), // Express.js v5 requires a RegExp object
      // prefix: '/public', // Compatible with Express.js v4,

      urlRewrite: (req) => req.url.replace('/public', ''),
      target: 'http://localhost:3000',
      docs: {
        name: 'Public Service',
        endpoint: 'swagger.json',
        type: 'swagger'
      }
    },
    {
      prefix: new RegExp('/admin/.*'), // Express.js v5 requires a RegExp object
      // prefix: '/admin', // Compatible with Express.js v4,
      target: 'http://localhost:3001',
      middlewares: [
        /*
        require('express-jwt').expressjwt({
          secret: 'shhhhhhared-secret',
          algorithms: ['HS256'],
        }),
        */
      ]
    }
  ]
}).listen(PORT, () => {
  console.log(`API Gateway listening on ${PORT} port!`)
})

@jkyberneees jkyberneees merged commit f5cae0a into master Sep 28, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

Express 5.0 breaking change in wildcard patterns
1 participant