Update proxying, swap /zammad and /link

This commit is contained in:
Darren Clarke 2025-02-06 13:03:31 +01:00
parent 2fd85f045c
commit 9283227074
24 changed files with 3317 additions and 2822 deletions

View file

@ -14,27 +14,27 @@
},
"dependencies": {
"@auth/kysely-adapter": "^1.5.2",
"@link-stack/bridge-common": "*",
"@link-stack/bridge-ui": "*",
"@link-stack/ui": "*",
"@mui/icons-material": "^5",
"@mui/material": "^5",
"@mui/material-nextjs": "^5",
"@mui/x-license": "^7.18.0",
"@link-stack/bridge-common": "*",
"@link-stack/bridge-ui": "*",
"next": "14.2.13",
"next": "^14.2.23",
"next-auth": "^4.24.8",
"react": "18.3.1",
"react-dom": "18.3.1",
"sharp": "^0.33.5",
"tsx": "^4.19.1",
"@link-stack/ui": "*"
"tsx": "^4.19.1"
},
"devDependencies": {
"@link-stack/eslint-config": "*",
"@link-stack/typescript-config": "*",
"@types/node": "^22",
"@types/pg": "^8.11.10",
"@types/react": "^18",
"@types/react-dom": "^18",
"@link-stack/eslint-config": "*",
"@link-stack/typescript-config": "*",
"typescript": "^5"
}
}

View file

@ -27,7 +27,7 @@
"date-fns": "^4.1.0",
"http-proxy-middleware": "^3.0.2",
"material-ui-popup-state": "^5.3.1",
"next": "14.2.13",
"next": "^14.2.23",
"next-auth": "^4.24.8",
"react": "18.3.1",
"react-cookie": "^7.2.0",
@ -39,11 +39,11 @@
"uuid": "^10.0.0"
},
"devDependencies": {
"@link-stack/eslint-config": "*",
"@link-stack/typescript-config": "*",
"@types/node": "^22.7.3",
"@types/react": "18.3.9",
"@types/uuid": "^10.0.0",
"@link-stack/eslint-config": "*",
"@link-stack/typescript-config": "*",
"typescript": "5.6.2"
}
}

View file

@ -477,14 +477,6 @@ export const Sidebar: FC<SidebarProps> = ({
/>
</List>
</Collapse>
<MenuItem
name="Knowledge Base"
href="/knowledge"
Icon={SchoolIcon}
iconSize={20}
selected={pathname.endsWith("/knowledge")}
open={open}
/>
<MenuItem
name="Documentation"
href="/docs"
@ -493,14 +485,6 @@ export const Sidebar: FC<SidebarProps> = ({
selected={pathname.endsWith("/docs")}
open={open}
/>
<MenuItem
name="Reporting"
href="/reporting"
Icon={AssessmentIcon}
iconSize={20}
selected={pathname.endsWith("/reporting")}
open={open}
/>
{leafcutterEnabled && (
<MenuItem
name="Leafcutter"
@ -557,14 +541,6 @@ export const Sidebar: FC<SidebarProps> = ({
/>
</List>
</Collapse>
<MenuItem
name="Profile"
href="/profile"
Icon={PersonIcon}
iconSize={20}
selected={pathname.endsWith("/profile")}
open={open}
/>
{roles.includes("admin") && (
<>
<MenuItem
@ -631,36 +607,10 @@ export const Sidebar: FC<SidebarProps> = ({
/>
</List>
</Collapse>
<MenuItem
name="Zammad Settings"
href="/admin/zammad"
Icon={FeaturedPlayListIcon}
iconSize={0}
selected={pathname.endsWith("/admin/zammad")}
open={open}
/>
{roles.includes("label_studio") && (
<MenuItem
name="Label Studio"
href="/admin/label-studio"
Icon={FeaturedPlayListIcon}
iconSize={0}
selected={pathname.endsWith("/admin/label-studio")}
open={open}
/>
)}
</List>
</Collapse>
</>
)}
<MenuItem
name="Zammad Interface"
href="/zammad"
Icon={DvrIcon}
iconSize={20}
open={open}
target="_blank"
/>
<MenuItem
name="Logout"
href="/logout"

View file

@ -20,7 +20,7 @@ export const MultiProvider: FC<PropsWithChildren> = ({ children }) => {
const locale = "en";
return (
<SessionProvider>
<SessionProvider basePath="/link/api/auth">
<CssBaseline />
<ZammadLoginProvider>
<CookiesProvider>

View file

@ -1,6 +1,7 @@
import { NextResponse } from "next/server";
import { withAuth, NextRequestWithAuth } from "next-auth/middleware";
/*
const rewriteURL = (
request: NextRequestWithAuth,
originBaseURL: string,
@ -25,31 +26,16 @@ const rewriteURL = (
request: { headers: requestHeaders },
});
};
*/
const checkRewrites = async (request: NextRequestWithAuth) => {
const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000";
const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080";
const zammadPaths = [
"/zammad",
"/auth/sso",
"/assets",
"/mobile",
"/graphql",
"/cable",
];
// const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000";
const { token } = request.nextauth;
const email = token?.email?.toLowerCase() ?? "unknown";
let headers = { "x-forwarded-user": email };
// let headers = { "x-forwarded-user": email };
if (request.nextUrl.pathname.startsWith("/zammad")) {
return rewriteURL(request, `${linkBaseURL}/zammad`, zammadURL, headers);
} else if (zammadPaths.some((p) => request.nextUrl.pathname.startsWith(p))) {
return rewriteURL(request, linkBaseURL, zammadURL, headers);
} else {
const isDev = process.env.NODE_ENV === "development";
const nonce = Buffer.from(crypto.randomUUID()).toString("base64");
const cspHeader = `
const isDev = process.env.NODE_ENV === "development";
const nonce = Buffer.from(crypto.randomUUID()).toString("base64");
const cspHeader = `
default-src 'self';
connect-src 'self';
script-src 'self' 'nonce-${nonce}' 'strict-dynamic' ${isDev ? "'unsafe-eval'" : ""};
@ -62,30 +48,29 @@ const checkRewrites = async (request: NextRequestWithAuth) => {
frame-ancestors 'none';
upgrade-insecure-requests;
`;
const contentSecurityPolicyHeaderValue = cspHeader
.replace(/\s{2,}/g, " ")
.trim();
const contentSecurityPolicyHeaderValue = cspHeader
.replace(/\s{2,}/g, " ")
.trim();
const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-nonce", nonce);
requestHeaders.set(
"Content-Security-Policy",
contentSecurityPolicyHeaderValue,
);
const requestHeaders = new Headers(request.headers);
requestHeaders.set("x-nonce", nonce);
requestHeaders.set(
"Content-Security-Policy",
contentSecurityPolicyHeaderValue,
);
const response = NextResponse.next({
request: {
headers: requestHeaders,
},
});
const response = NextResponse.next({
request: {
headers: requestHeaders,
},
});
response.headers.set(
"Content-Security-Policy",
contentSecurityPolicyHeaderValue,
);
response.headers.set(
"Content-Security-Policy",
contentSecurityPolicyHeaderValue,
);
return response;
}
return response;
};
export default withAuth(checkRewrites, {

View file

@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
basePath: '/link',
poweredByHeader: false,
transpilePackages: [
"@link-stack/leafcutter-ui",
@ -30,20 +31,6 @@ const nextConfig = {
},
];
},
rewrites: async () => {
return {
beforeFiles: [
{
source: "/api/v1/:path*",
destination: `${process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080"}/api/v1/:path*`,
},
{
source: "/ws",
destination: `${process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080"}/ws`,
},
],
};
},
};
export default nextConfig;

View file

@ -31,7 +31,7 @@
"date-fns": "^4.1.0",
"graphql-request": "^7.1.0",
"mui-chips-input": "^2.1.5",
"next": "14.2.13",
"next": "^14.2.23",
"next-auth": "^4.24.8",
"react": "18.3.1",
"react-cookie": "^7.2.0",