From 781f8c380a58933745b966e3d8d5b5f7bd47da9a Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Wed, 28 Aug 2024 10:06:43 +0200 Subject: [PATCH] Rewrite Zammad API calls in config rather than middleware --- apps/link/Dockerfile | 1 + apps/link/middleware.ts | 5 +---- apps/link/next.config.js | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/apps/link/Dockerfile b/apps/link/Dockerfile index de7bb3b..42b2eeb 100644 --- a/apps/link/Dockerfile +++ b/apps/link/Dockerfile @@ -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 diff --git a/apps/link/middleware.ts b/apps/link/middleware.ts index e1ffdbd..3eaa8d1 100644 --- a/apps/link/middleware.ts +++ b/apps/link/middleware.ts @@ -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).*)", ], }; diff --git a/apps/link/next.config.js b/apps/link/next.config.js index 77f6b6f..cf9c411 100644 --- a/apps/link/next.config.js +++ b/apps/link/next.config.js @@ -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;