Rewrite Zammad API calls in config rather than middleware

This commit is contained in:
Darren Clarke 2024-08-28 10:06:43 +02:00
parent f0e8e20c24
commit 781f8c380a
3 changed files with 17 additions and 5 deletions

View file

@ -18,6 +18,7 @@ RUN npm ci
COPY --from=builder ${APP_DIR}/out/full/ .
RUN npm i -g turbo
ENV ZAMMAD_URL=http://zammad-nginx:8080
RUN turbo run build --filter=@link-stack/link --filter=@link-stack/bridge-migrations
FROM base AS runner

View file

@ -70,9 +70,6 @@ export default withAuth(checkRewrites, {
callbacks: {
authorized: ({ token, req }) => {
const path = req.nextUrl.pathname;
if (path.startsWith("/api/v1/")) {
return true;
}
if (process.env.SETUP_MODE === "true") {
return true;
@ -95,6 +92,6 @@ export default withAuth(checkRewrites, {
export const config = {
matcher: [
"/((?!ws|wss|api/signal|api/whatsapp|api/facebook|_next/static|_next/image|favicon.ico).*)",
"/((?!ws|wss|api/v1|api/signal|api/whatsapp|api/facebook|_next/static|_next/image|favicon.ico).*)",
],
};

View file

@ -6,7 +6,7 @@ const nextConfig = {
"@link-stack/ui",
"@link-stack/bridge-common",
"@link-stack/bridge-ui",
"mui-chips-input"
"mui-chips-input",
],
publicRuntimeConfig: {
linkURL: process.env.LINK_URL ?? "http://localhost:3000",
@ -14,6 +14,20 @@ const nextConfig = {
labelStudioURL: process.env.LABEL_STUDIO_URL ?? "http://localhost:8006",
muiLicenseKey: process.env.MUI_LICENSE_KEY ?? "",
},
rewrites: async () => {
return {
beforeFiles: [
{
source: "/api/v1/:path*",
destination: `${process.env.ZAMMAD_URL}/api/v1/:path*`,
},
{
source: "/ws",
destination: `${process.env.ZAMMAD_URL}/ws`,
},
],
};
},
};
export default nextConfig;