Wesley Gomes
Wesley Gomes
NNuxt
Created by Wesley Gomes on 1/8/2025 in #❓・help
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. * code snippet: server-middleware/proxy.js *
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");

const app = express();

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;
const express = require("express");
const { createProxyMiddleware } = require("http-proxy-middleware");

const app = express();

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;
` call in nuxt.config.js
serverMiddleware: ["~/server-middleware/proxy.js"],
serverMiddleware: ["~/server-middleware/proxy.js"],
`
15 replies