Move metamigo assets to metamigo-add

This commit is contained in:
Darren Clarke 2023-08-25 11:04:38 +02:00
parent aab5b7f5d5
commit 28f7f0f47b
71 changed files with 3 additions and 2 deletions

View file

@ -1,30 +0,0 @@
import { createProxyMiddleware } from "http-proxy-middleware";
export const POST = createProxyMiddleware({
target:
process.env.NODE_ENV === "production"
? "http://metamigo-api:3001"
: "http://127.0.0.1:3001",
changeOrigin: true,
pathRewrite: { "^/graphql": "/graphql" },
xfwd: true,
onProxyReq(proxyReq, req, _res) {
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.");
}
},
});