Middleware and iframe updates

This commit is contained in:
Darren Clarke 2023-03-01 11:02:15 +00:00
parent d7624d723f
commit ba04aa108c
29 changed files with 69 additions and 4128 deletions

View file

@ -0,0 +1,39 @@
import { NextApiRequest, NextApiResponse } from 'next';
import { createProxyMiddleware } from 'http-proxy-middleware';
import { getToken } from "next-auth/jwt";
const withAuthInfo =
(handler) => async (req: NextApiRequest, res: NextApiResponse) => {
const session = await getToken({
req,
secret: process.env.NEXTAUTH_SECRET,
});
if (!session) {
return res.redirect("/login");
}
req.headers['X-Forwarded-User'] = session.email.toLowerCase();
req.headers['Host'] = 'zammad.example.com';
console.log({ headers: req.headers })
return handler(req, res);
};
const proxy = createProxyMiddleware({
target: process.env.ZAMMAD_URL,
changeOrigin: true,
xfwd: true,
ws: true,
pathRewrite: { "^/zammad": "" },
});
export default withAuthInfo(proxy);
export const config = {
api: {
bodyParser: false,
externalResolver: true,
},
};