Cleanup live changes
This commit is contained in:
parent
d0f9e8bb65
commit
6a85c644dc
3 changed files with 22 additions and 20 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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')) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue