I have an Express middleware that renders React on the server like so, placed at the end, after all other routes:
app.use(function(req, res) {
Router.run(routes, req.path, function(Handler) {
var markup = React.renderToString(<Handler />);
res.send(swig.renderFile('views/index.html', { html: markup }));
});
});
Since no route is specified this middleware will execute for all requests. I would like to exclude all /api
routes from it. The problem is even if I create all API routes before this middleware, there is always a possibility for this middleware to be executed on /api/nonexistantendpoint
path.
To be more precise, I am looking for a regex that would make this middleware execute for all paths except any path starting with /api
.
Thanks!
I have already looked at this SO post but couldn't find anything useful to me.
And this post contains a lot of workarounds which is also not what I am looking for.
This post asks you to conditionally check for URL inside the middleware.