Changes from live

This commit is contained in:
Darren Clarke 2023-06-05 14:48:23 +00:00
parent d2522521dd
commit d0f9e8bb65
11 changed files with 22076 additions and 22031 deletions

View file

@ -18,6 +18,7 @@ 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_EMBEDDED=true
RUN npm i -g turbo RUN npm i -g turbo
RUN turbo run build --filter=leafcutter RUN turbo run build --filter=leafcutter

View file

@ -13,11 +13,13 @@ 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

@ -1,6 +1,6 @@
module.exports = { module.exports = {
publicRuntimeConfig: { publicRuntimeConfig: {
embedded: Boolean(process.env.LINK_EMBEDDED), embedded: true
}, },
basePath: "/proxy/leafcutter", basePath: "/proxy/leafcutter",
assetPrefix: "/proxy/leafcutter", assetPrefix: "/proxy/leafcutter",

View file

@ -18,6 +18,7 @@ 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

@ -335,13 +335,13 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
/> />
<MenuItem <MenuItem
name="Tickets" name="Tickets"
href="/tickets/assigned" href="/tickets/3"
Icon={FeaturedPlayListIcon} Icon={FeaturedPlayListIcon}
selected={pathname.startsWith("/tickets")} selected={pathname.startsWith("/tickets")}
iconSize={20} iconSize={20}
open={open} open={open}
/> />
{/*
<Collapse <Collapse
in={pathname.startsWith("/tickets")} in={pathname.startsWith("/tickets")}
timeout="auto" timeout="auto"
@ -387,15 +387,15 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
/> />
<MenuItem <MenuItem
name="New Ticket UI" name="New Ticket UI"
href="/tickets/2" href="/tickets/3"
Icon={SettingsIcon} Icon={SettingsIcon}
iconSize={0} iconSize={0}
selected={pathname.endsWith("/tickets/2")} selected={pathname.endsWith("/tickets/3")}
open={open} open={open}
/> />
</List> </List>
</Collapse> </Collapse>
*/ }
<MenuItem <MenuItem
name="Knowledge Base" name="Knowledge Base"
href="/knowledge" href="/knowledge"
@ -406,7 +406,7 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
/> />
<MenuItem <MenuItem
name="Leafcutter" name="Leafcutter"
href="/leafcutter" href="/leafcutter/about"
Icon={AnalyticsIcon} Icon={AnalyticsIcon}
iconSize={20} iconSize={20}
selected={pathname.endsWith("/leafcutter")} selected={pathname.endsWith("/leafcutter")}
@ -419,6 +419,7 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
onClick={undefined} onClick={undefined}
> >
<List component="div" disablePadding> <List component="div" disablePadding>
{/*
<MenuItem <MenuItem
name="Dashboard" name="Dashboard"
href="/leafcutter" href="/leafcutter"
@ -442,7 +443,7 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
selected={pathname.endsWith("/leafcutter/trends")} selected={pathname.endsWith("/leafcutter/trends")}
open={open} open={open}
/> />
*/}
<MenuItem <MenuItem
name="FAQ" name="FAQ"
href="/leafcutter/faq" href="/leafcutter/faq"

View file

@ -1,7 +1,6 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server'; import type { NextRequest } from 'next/server';
import { withAuth } from "next-auth/middleware"; import { withAuth, NextRequestWithAuth } from "next-auth/middleware";
import { getToken } from "next-auth/jwt";
const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBaseURL: string, headers: any = {}) => { const rewriteURL = (request: NextRequest, originBaseURL: string, destinationBaseURL: string, headers: any = {}) => {
if (request.nextUrl.pathname.includes('/_next/static/development/')) { if (request.nextUrl.pathname.includes('/_next/static/development/')) {
@ -11,31 +10,51 @@ 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}`);
return NextResponse.rewrite(new URL(destinationURL), { ...request.headers, ...headers }); const requestHeaders = new Headers(request.headers);
for (const [key, value] of Object.entries(headers)) {
// @ts-ignore
requestHeaders.set(key, value);
}
requestHeaders.delete('connection');
console.log({finalHeaders: requestHeaders});
return NextResponse.rewrite(new URL(destinationURL), { request: { headers: requestHeaders } });
}; };
const checkRewrites = async (request: NextRequest) => { const checkRewrites = async (request: NextRequestWithAuth) => {
console.log({currentURL: request.nextUrl.href});
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, process.env.LINK_URL, process.env.LEAFCUTTER_URL); return rewriteURL(request, linkBaseURL, "http://leafcutter:3000");
} else if (request.nextUrl.pathname.startsWith('/proxy/metamigo')) { } else if (request.nextUrl.pathname.startsWith('/proxy/metamigo')) {
return rewriteURL(request, process.env.LINK_URL, process.env.METAMIGO_URL); return rewriteURL(request, linkBaseURL, "http://metamigo:3000");
} else if (request.nextUrl.pathname.startsWith('/proxy/zammad')) { } else if (request.nextUrl.pathname.startsWith('/proxy/zammad')) {
const session = await getToken({ console.log('proxying to zammad');
req: request, const { token } = request.nextauth;
secret: process.env.NEXTAUTH_SECRET,
}); console.log({nextauth: request.nextauth});
const headers = { const headers = {
'X-Forwarded-User': session.email.toLowerCase(), 'X-Forwarded-User': token.email.toLowerCase(),
host: 'zammad.example.com' host: 'link-stack-dev.digiresilience.org'
}; };
return rewriteURL(request, `${process.env.LINK_URL}/proxy/zammad`, process.env.ZAMMAD_URL, headers); console.log({headers});
} else if (request.nextUrl.pathname.startsWith('/assets')) {
return rewriteURL(request, `${linkBaseURL}/proxy/zammad`, zammadURL, headers);
} else if (request.nextUrl.pathname.startsWith('/assets') || request.nextUrl.pathname.startsWith('/api/v1')) {
console.log('asset'); console.log('asset');
return rewriteURL(request, `${process.env.LINK_URL}`, process.env.ZAMMAD_URL); return rewriteURL(request, linkBaseURL, zammadURL);
} else if (request.nextUrl.pathname.startsWith('/proxy/assets') || request.nextUrl.pathname.startsWith('/proxy/api')) { } else if (request.nextUrl.pathname.startsWith('/proxy/assets')) {
console.log('proxy asset'); console.log('proxy asset');
return rewriteURL(request, `${process.env.LINK_URL}/proxy`, process.env.ZAMMAD_URL); return rewriteURL(request, `${linkBaseURL}/proxy`, zammadURL);
} else if (request.nextUrl.pathname.startsWith('/proxy/api')) {
console.log('proxy api');
return rewriteURL(request, `${linkBaseURL}/proxy`, zammadURL);
} }
}; };
@ -71,4 +90,3 @@ export default withAuth(
} }
} }
); );

View file

@ -6,6 +6,16 @@ const nextConfig = {
leafcutterURL: process.env.LEAFCUTTER_URL, leafcutterURL: process.env.LEAFCUTTER_URL,
metamigoURL: process.env.METAMIGO_URL, metamigoURL: process.env.METAMIGO_URL,
}, },
async rewrites() {
return {
fallback: [
{
source: '/:path*',
destination: `/proxy/zammad/:path*`,
},
],
}
}
}; };
module.exports = nextConfig; module.exports = nextConfig;

View file

@ -0,0 +1,5 @@
import { NextApiRequest, NextApiResponse } from 'next';
export default function handler(req: NextApiRequest, res: NextApiResponse) {
res.redirect(307, '/proxy/zammad/api/v1' + req.url.substring('/api/v1'.length));
}

View file

@ -49,7 +49,7 @@ const Login: FC<LoginProps> = ({ session }) => {
sx={buttonStyles} sx={buttonStyles}
onClick={() => onClick={() =>
signIn("google", { signIn("google", {
callbackUrl: `${origin}/auth/sso`, callbackUrl: `${origin}/proxy/zammad/auth/sso`,
}) })
} }
> >

View file

@ -227,6 +227,9 @@ services:
ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN} ZAMMAD_API_TOKEN: ${ZAMMAD_API_TOKEN}
ZAMMAD_VIRUAL_HOST: ${ZAMMAD_VIRTUAL_HOST} ZAMMAD_VIRUAL_HOST: ${ZAMMAD_VIRTUAL_HOST}
LINK_URL: ${LINK_URL} LINK_URL: ${LINK_URL}
LEAFCUTTER_URL: http://leafcutter:3000
METAMIGO_URL: http://metamigo-frontend:3000
ZAMMAD_URL: http://zammad-nginx:8080
NEXTAUTH_URL: ${LINK_URL} NEXTAUTH_URL: ${LINK_URL}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET} NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE} NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE}
@ -246,6 +249,11 @@ services:
- "8004:3000" - "8004:3000"
environment: environment:
LINK_EMBEDDED: "true" LINK_EMBEDDED: "true"
NEXTAUTH_URL: ${LINK_URL}
NEXTAUTH_SECRET: ${NEXTAUTH_SECRET}
NEXTAUTH_AUDIENCE: ${NEXTAUTH_AUDIENCE}
NEXTAUTH_SIGNING_KEY_B64: ${NEXTAUTH_SIGNING_KEY_B64}
NEXTAUTH_ENCRYPTION_KEY_B64: ${NEXTAUTH_ENCRYPTION_KEY_B64}
volumes: volumes:
elasticsearch-data: elasticsearch-data:

44005
package-lock.json generated

File diff suppressed because it is too large Load diff