Middleware and iframe updates
This commit is contained in:
parent
d7624d723f
commit
ba04aa108c
29 changed files with 69 additions and 4128 deletions
39
apps/link/pages/api/proxy/[[...path]].ts
Normal file
39
apps/link/pages/api/proxy/[[...path]].ts
Normal 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,
|
||||
},
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue