Skip to content

Express 5.0 breaking change in wildcard patterns #94

@wonder-bread

Description

@wonder-bread

Hello. As of release 5.0.0 of expressjs, a change in pattern styling via the path-to-regexp package has broken wildcard Express.js routing paths. As a consequence of this, the default pathRegex property within fast-gateway now appears to be broken. Routes that do not provide an explicit pathRegex property (e.g., a route named /api, which would have a generated path of /api/*) produce the error described within the following thread and cause applications utilizing fast-gateway to error out:

expressjs/express#5936 (comment)

Notably, updating the opts object's pathRegex property from /* to /*regex within the fast-gateway source code appears to fix this, but truthfully, I am not confident that this is the "intended" solution per the Express thread linked above -- or else I would have submitted this as a PR :) Please advise! We've been using fast-gateway for years and it's been great for our use case.

opts = Object.assign({
  middlewares: [],
  pathRegex: '/*regex'
}, opts)

To Reproduce

  1. Initialize a bare npm repository
  2. npm i express@^5.0.0
  3. npm i fast-gateway
  4. Run the following snippet of code:
const gateway = require("fast-gateway");
const express = require("express");

const app = express();

const routes = [
  {
    prefix: "/api",
    target: "http://localhost:1111",
  },
];

const server = gateway({ routes, server: app });

server.listen(1234, () => {
  console.log(`\nGateway communication started on port 1234.`);
});

This will produce the error attached in the Screenshots section below.

Expected behavior
The console.log call will be produced within the relevant terminal. Speaking more broadly, wildcard prefixes should continue to work without issue.

Screenshots
Error produced:
image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions