servermiddleware routes are not recognized in production
My application communicates with several miscroservices, and I need to "hide" the API routes from the client, I'm trying the servermiddleware approach, on site it works, but when I go up to production it recognizes the route as being from the front and returns an html.
app.use(
"/api/notifications",
createProxyMiddleware({
target: process.env.API_NOTIFICATIONS,
changeOrigin: true,
})
);
app.use(
"/api/customers",
createProxyMiddleware({
target: process.env.API_CUSTOMERS,
changeOrigin: true,
})
);
module.exports = app;
js
serverMiddleware: ["~/server-middleware/proxy.js"],
````
- code snippet: server-middleware/proxy.js *
```js
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");
app.use(
"/api/notifications",
createProxyMiddleware({
target: process.env.API_NOTIFICATIONS,
changeOrigin: true,
})
);
app.use(
"/api/customers",
createProxyMiddleware({
target: process.env.API_CUSTOMERS,
changeOrigin: true,
})
);
module.exports = app;
js
serverMiddleware: ["~/server-middleware/proxy.js"],
````
