From 6a85c644dc7559335d264bb86166dbf9b12c749b Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Mon, 5 Jun 2023 15:00:46 +0000 Subject: [PATCH] Cleanup live changes --- apps/leafcutter/components/Layout.tsx | 4 --- apps/link/Dockerfile | 1 - apps/link/middleware.ts | 37 ++++++++++++++++----------- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/apps/leafcutter/components/Layout.tsx b/apps/leafcutter/components/Layout.tsx index b1f2c5b..9c6a158 100644 --- a/apps/leafcutter/components/Layout.tsx +++ b/apps/leafcutter/components/Layout.tsx @@ -11,15 +11,11 @@ import { useAppContext } from "./AppProvider"; export const Layout: FC = ({ children }) => { const [cookies, setCookie] = useCookies(["cookieConsent"]); - const consentGranted = cookies.cookieConsent === "true"; -/* const { publicRuntimeConfig: { embedded }, } = getConfig(); -*/ - const embedded = true; const { colors: { white, diff --git a/apps/link/Dockerfile b/apps/link/Dockerfile index 7add7be..de05bfb 100644 --- a/apps/link/Dockerfile +++ b/apps/link/Dockerfile @@ -18,7 +18,6 @@ COPY --from=builder ${APP_DIR}/out/package-lock.json ./package-lock.json RUN npm ci --omit=dev COPY --from=builder ${APP_DIR}/out/full/ . -ARG LINK_URL=https://link-stack-dev.digiresilience.org RUN npm i -g turbo RUN turbo run build --filter=link diff --git a/apps/link/middleware.ts b/apps/link/middleware.ts index 321023f..b396250 100644 --- a/apps/link/middleware.ts +++ b/apps/link/middleware.ts @@ -3,6 +3,10 @@ import type { NextRequest } from 'next/server'; import { withAuth, NextRequestWithAuth } from "next-auth/middleware"; const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBaseURL: string, headers: any = {}) => { + if (request.nextUrl.protocol.startsWith('ws')) { + return NextResponse.next(); + } + if (request.nextUrl.pathname.includes('/_next/static/development/')) { return NextResponse.next(); } @@ -10,40 +14,43 @@ const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBase const destinationURL = request.url.replace(originBaseURL, destinationBaseURL); console.log(`Rewriting ${request.url} to ${destinationURL}`); -const requestHeaders = new Headers(request.headers); -for (const [key, value] of Object.entries(headers)) { -// @ts-ignore - requestHeaders.set(key, value); -} + const requestHeaders = new Headers(request.headers); + for (const [key, value] of Object.entries(headers)) { + // @ts-ignore + requestHeaders.set(key, value); + } -requestHeaders.delete('connection'); + requestHeaders.delete('connection'); -console.log({finalHeaders: requestHeaders}); + console.log({ finalHeaders: requestHeaders }); return NextResponse.rewrite(new URL(destinationURL), { request: { headers: requestHeaders } }); }; const checkRewrites = async (request: NextRequestWithAuth) => { -console.log({currentURL: request.nextUrl.href}); + console.log({ currentURL: request.nextUrl.href }); + + const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000"; + const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080"; + const leafcutterURL = process.env.LEAFCUTTER_URL ?? "http://leafcutter:3000"; + const metamigoURL = process.env.METAMIGO_URL ?? "http://metamigo:3000"; - const linkBaseURL = "http://localhost:3000"; - const zammadURL = "http://zammad-nginx:8080"; if (request.nextUrl.pathname.startsWith('/proxy/leafcutter')) { - return rewriteURL(request, linkBaseURL, "http://leafcutter:3000"); + return rewriteURL(request, linkBaseURL, leafcutterURL); } else if (request.nextUrl.pathname.startsWith('/proxy/metamigo')) { - return rewriteURL(request, linkBaseURL, "http://metamigo:3000"); + return rewriteURL(request, linkBaseURL, metamigoURL); } else if (request.nextUrl.pathname.startsWith('/proxy/zammad')) { -console.log('proxying to zammad'); + console.log('proxying to zammad'); const { token } = request.nextauth; - console.log({nextauth: request.nextauth}); + console.log({ nextauth: request.nextauth }); const headers = { 'X-Forwarded-User': token.email.toLowerCase(), host: 'link-stack-dev.digiresilience.org' }; -console.log({headers}); + console.log({ headers }); return rewriteURL(request, `${linkBaseURL}/proxy/zammad`, zammadURL, headers); } else if (request.nextUrl.pathname.startsWith('/assets') || request.nextUrl.pathname.startsWith('/api/v1')) {