Add all repos
This commit is contained in:
parent
faa12c60bc
commit
8a91c9b89b
369 changed files with 29047 additions and 28 deletions
38
metamigo-frontend/pages/api/proxy/[[...path]].js
Normal file
38
metamigo-frontend/pages/api/proxy/[[...path]].js
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
import { createProxyMiddleware } from "http-proxy-middleware";
|
||||
|
||||
export default createProxyMiddleware({
|
||||
target:
|
||||
process.env.NODE_ENV === "production"
|
||||
? "http://metamigo-api:3001"
|
||||
: "http://localhost:3001",
|
||||
changeOrigin: true,
|
||||
pathRewrite: { "^/api/v1": "/api" },
|
||||
xfwd: true,
|
||||
onProxyReq: function (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
|
||||
//const token = req.cookies["next-auth.session-token"];
|
||||
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.");
|
||||
}
|
||||
return;
|
||||
},
|
||||
});
|
||||
|
||||
export const config = {
|
||||
api: {
|
||||
bodyParser: false,
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue