App directory #4

This commit is contained in:
Darren Clarke 2023-06-28 12:55:24 +00:00 committed by GitHub
parent 69706053c6
commit 4d743c5e67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 223 additions and 107 deletions

View file

@ -1,37 +0,0 @@
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(proxyReq, req) {
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.");
}
},
});
export const config = {
api: {
bodyParser: false,
},
};