Cleanup live changes

This commit is contained in:
Darren Clarke 2023-06-05 15:00:46 +00:00 committed by GitHub
parent d0f9e8bb65
commit 6a85c644dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 20 deletions

View file

@ -11,15 +11,11 @@ import { useAppContext } from "./AppProvider";
export const Layout: FC<PropsWithChildren> = ({ children }) => { export const Layout: FC<PropsWithChildren> = ({ children }) => {
const [cookies, setCookie] = useCookies(["cookieConsent"]); const [cookies, setCookie] = useCookies(["cookieConsent"]);
const consentGranted = cookies.cookieConsent === "true"; const consentGranted = cookies.cookieConsent === "true";
/*
const { const {
publicRuntimeConfig: { embedded }, publicRuntimeConfig: { embedded },
} = getConfig(); } = getConfig();
*/
const embedded = true;
const { const {
colors: { colors: {
white, white,

View file

@ -18,7 +18,6 @@ COPY --from=builder ${APP_DIR}/out/package-lock.json ./package-lock.json
RUN npm ci --omit=dev RUN npm ci --omit=dev
COPY --from=builder ${APP_DIR}/out/full/ . COPY --from=builder ${APP_DIR}/out/full/ .
ARG LINK_URL=https://link-stack-dev.digiresilience.org
RUN npm i -g turbo RUN npm i -g turbo
RUN turbo run build --filter=link RUN turbo run build --filter=link

View file

@ -3,6 +3,10 @@ import type { NextRequest } from 'next/server';
import { withAuth, NextRequestWithAuth } from "next-auth/middleware"; import { withAuth, NextRequestWithAuth } from "next-auth/middleware";
const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBaseURL: string, headers: any = {}) => { 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/')) { if (request.nextUrl.pathname.includes('/_next/static/development/')) {
return NextResponse.next(); return NextResponse.next();
} }
@ -10,40 +14,43 @@ const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBase
const destinationURL = request.url.replace(originBaseURL, destinationBaseURL); const destinationURL = request.url.replace(originBaseURL, destinationBaseURL);
console.log(`Rewriting ${request.url} to ${destinationURL}`); console.log(`Rewriting ${request.url} to ${destinationURL}`);
const requestHeaders = new Headers(request.headers); const requestHeaders = new Headers(request.headers);
for (const [key, value] of Object.entries(headers)) { for (const [key, value] of Object.entries(headers)) {
// @ts-ignore // @ts-ignore
requestHeaders.set(key, value); 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 } }); return NextResponse.rewrite(new URL(destinationURL), { request: { headers: requestHeaders } });
}; };
const checkRewrites = async (request: NextRequestWithAuth) => { 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')) { 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')) { } 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')) { } else if (request.nextUrl.pathname.startsWith('/proxy/zammad')) {
console.log('proxying to zammad'); console.log('proxying to zammad');
const { token } = request.nextauth; const { token } = request.nextauth;
console.log({nextauth: request.nextauth}); console.log({ nextauth: request.nextauth });
const headers = { const headers = {
'X-Forwarded-User': token.email.toLowerCase(), 'X-Forwarded-User': token.email.toLowerCase(),
host: 'link-stack-dev.digiresilience.org' host: 'link-stack-dev.digiresilience.org'
}; };
console.log({headers}); console.log({ headers });
return rewriteURL(request, `${linkBaseURL}/proxy/zammad`, zammadURL, headers); return rewriteURL(request, `${linkBaseURL}/proxy/zammad`, zammadURL, headers);
} else if (request.nextUrl.pathname.startsWith('/assets') || request.nextUrl.pathname.startsWith('/api/v1')) { } else if (request.nextUrl.pathname.startsWith('/assets') || request.nextUrl.pathname.startsWith('/api/v1')) {