'Wildcard express route

I'm using express to serve my angular bundle:

const server = express();
server.use('/', signupPost);
server.use('/', loginPost);
server.use('/', facebookAuthGet);
server.use('/', googleAuthGet);
server.use('/', storePatch);

// expose the other assets for the html to reference
server.use(express.static(path.join(__dirname, dirPrefix, 'frontend')));
// serve our bundle
server.use('*', express.static(path.join(__dirname, dirPrefix, 'frontend/index.html')));

server.listen(port, () => {
  logger.info(`Server started at ${process.env.DOMAIN}`);
});

This works well and fine for all routes EXCEPT for those ending in a trailing slash. E.g. /test would hit the bundle (to be handled by the SPA), but /test/ does not and returns

Cannot GET /test/

I've tried to match */*, ** and */ without success. How can I get express to treat /test/ the same as /test?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source