I have an express app set up using http-proxy-middleware, but I'm having a problem routing only a subset of requests through the proxy.
Here is what my config looks like:
app.use(/\/.*-img/i, proxy({changeOrigin: true, logLevel: 'debug', target: 'http://ucassets.blob.core.windows.net'}));
app.get('*', (req, res) => {
const location = req.url;
const memoryHistory = createMemoryHistory(req.originalUrl);
const store = configureStore(memoryHistory);
const history = syncHistoryWithStore(memoryHistory, store);
match({history, routes, location},
(error, redirectLocation, renderProps) => {
if (error) {
res.status(500).send(error.message);
} else if (redirectLocation) {
res.redirect(302, redirectLocation.pathname + redirectLocation.search);
} else if (renderProps) {
/* render HTML and send code 200 */
} else {
res.status(404).send('Not Found?');
}
});
});
The proxy route sometimes works, and other times ends up printing that "Not found?" 404 result. Of note, there is NOT a route in my react-router config that matches the proxy route above. Since both routes technically match the express route, I guess express is randomly choosing which one to execute?
EDIT: Here's an example route that is being problematic:
/user-img/bc070850-11c9-a79e-2881-9bd6cc04c3ca.jpg