2023-02-13 12:41:30 +00:00
|
|
|
import { createProxyMiddleware } from "http-proxy-middleware";
|
|
|
|
|
|
|
|
|
|
export default createProxyMiddleware({
|
|
|
|
|
target:
|
|
|
|
|
process.env.NODE_ENV === "production"
|
|
|
|
|
? "http://metamigo-api:3001"
|
2023-06-06 11:46:35 +00:00
|
|
|
: "http://127.0.0.1:3001",
|
2023-02-13 12:41:30 +00:00
|
|
|
changeOrigin: true,
|
|
|
|
|
pathRewrite: { "^/graphql": "/graphql" },
|
|
|
|
|
xfwd: true,
|
2023-03-15 12:17:43 +00:00
|
|
|
onProxyReq(proxyReq, req, _res) {
|
2023-02-13 12:41:30 +00:00
|
|
|
const auth = proxyReq.getHeader("authorization");
|
|
|
|
|
if (auth) {
|
|
|
|
|
// pass along user provided authorization header
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Else extract the session token from the cookie and pass
|
|
|
|
|
// as bearer token to the proxy target
|
|
|
|
|
let token = req.cookies["__Secure-next-auth.session-token"];
|
|
|
|
|
if (!token) token = req.cookies["next-auth.session-token"];
|
|
|
|
|
|
|
|
|
|
if (token) {
|
|
|
|
|
proxyReq.setHeader("authorization", `Bearer ${token}`);
|
|
|
|
|
proxyReq.removeHeader("cookie");
|
|
|
|
|
} else {
|
|
|
|
|
console.error("no token found. proxied request to backend will fail.");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export const config = {
|
|
|
|
|
api: {
|
|
|
|
|
bodyParser: false,
|
|
|
|
|
},
|
|
|
|
|
};
|