Middleware proxy updates
This commit is contained in:
parent
282808583b
commit
38d3e9349c
20 changed files with 329 additions and 224 deletions
|
|
@ -23,13 +23,13 @@
|
|||
"@mui/icons-material": "^5",
|
||||
"@mui/lab": "^5.0.0-alpha.137",
|
||||
"@mui/material": "^5",
|
||||
"@mui/x-data-grid-pro": "^6.10.0",
|
||||
"@mui/x-date-pickers-pro": "^6.10.0",
|
||||
"@mui/x-data-grid-pro": "^6.10.1",
|
||||
"@mui/x-date-pickers-pro": "^6.10.1",
|
||||
"@opensearch-project/opensearch": "^2.3.1",
|
||||
"date-fns": "^2.30.0",
|
||||
"http-proxy-middleware": "^2.0.6",
|
||||
"material-ui-popup-state": "^5.0.9",
|
||||
"next": "13.4.10",
|
||||
"next": "13.4.11",
|
||||
"next-auth": "^4.22.3",
|
||||
"next-http-proxy-middleware": "^1.2.5",
|
||||
"nodemailer": "^6.9.4",
|
||||
|
|
@ -53,12 +53,12 @@
|
|||
"babel-loader": "^9.1.3",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-config-next": "^13.4.10",
|
||||
"eslint-config-next": "^13.4.11",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react": "^7.33.0",
|
||||
"typescript": "5.1.6"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -166,11 +166,11 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
{
|
||||
document: getTicketOverviewCountsQuery,
|
||||
},
|
||||
{ refreshInterval: 10000 }
|
||||
{ refreshInterval: 10000 },
|
||||
);
|
||||
const findOverviewCountByID = (id: number) =>
|
||||
overviewData?.ticketOverviews?.edges?.find((overview: any) =>
|
||||
overview.node.id.endsWith(`/${id}`)
|
||||
overview.node.id.endsWith(`/${id}`),
|
||||
)?.node?.ticketCount ?? 0;
|
||||
const assignedCount = findOverviewCountByID(1);
|
||||
const urgentCount = findOverviewCountByID(7);
|
||||
|
|
@ -426,7 +426,7 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
/>
|
||||
<MenuItem
|
||||
name="Leafcutter"
|
||||
href="/leafcutter/about"
|
||||
href="/leafcutter"
|
||||
Icon={AnalyticsIcon}
|
||||
iconSize={20}
|
||||
selected={pathname.endsWith("/leafcutter")}
|
||||
|
|
@ -439,7 +439,6 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
onClick={undefined}
|
||||
>
|
||||
<List component="div" disablePadding>
|
||||
{/*
|
||||
<MenuItem
|
||||
name="Dashboard"
|
||||
href="/leafcutter"
|
||||
|
|
@ -447,7 +446,6 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
selected={pathname.endsWith("/leafcutter")}
|
||||
open={open}
|
||||
/>
|
||||
|
||||
<MenuItem
|
||||
name="Search and Create"
|
||||
href="/leafcutter/create"
|
||||
|
|
@ -455,7 +453,6 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
selected={pathname.endsWith("/leafcutter/create")}
|
||||
open={open}
|
||||
/>
|
||||
|
||||
<MenuItem
|
||||
name="Trends"
|
||||
href="/leafcutter/trends"
|
||||
|
|
@ -463,7 +460,6 @@ export const Sidebar: FC<SidebarProps> = ({ open, setOpen }) => {
|
|||
selected={pathname.endsWith("/leafcutter/trends")}
|
||||
open={open}
|
||||
/>
|
||||
*/}
|
||||
<MenuItem
|
||||
name="FAQ"
|
||||
href="/leafcutter/faq"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { FC, useState } from "react";
|
||||
import getConfig from "next/config";
|
||||
import { useRouter } from "next/navigation";
|
||||
import Iframe from "react-iframe";
|
||||
|
||||
|
|
@ -55,7 +54,7 @@ export const ZammadWrapper: FC<ZammadWrapperProps> = ({
|
|||
// @ts-ignore
|
||||
(
|
||||
linkElement.contentDocument.querySelector(
|
||||
".overview-header"
|
||||
".overview-header",
|
||||
) as any
|
||||
).style = "display: none";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ export const LabelStudioWrapper: FC = () => (
|
|||
>
|
||||
<Grid item sx={{ height: "100vh", width: "100%" }}>
|
||||
<Iframe
|
||||
id="link"
|
||||
url={"https://label-studio:3000"}
|
||||
id="label-studio"
|
||||
url={"/proxy/label-studio"}
|
||||
width="100%"
|
||||
height="100%"
|
||||
frameBorder={0}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import getConfig from "next/config";
|
||||
import { Grid } from "@mui/material";
|
||||
import Iframe from "react-iframe";
|
||||
|
||||
|
|
@ -10,11 +9,6 @@ type MetamigoWrapperProps = {
|
|||
};
|
||||
|
||||
export const MetamigoWrapper: FC<MetamigoWrapperProps> = ({ path }) => {
|
||||
const {
|
||||
publicRuntimeConfig: { linkURL },
|
||||
} = getConfig();
|
||||
const fullMetamigoURL = `${linkURL}/metamigo/${path}`;
|
||||
|
||||
return (
|
||||
<Grid
|
||||
container
|
||||
|
|
@ -24,8 +18,8 @@ export const MetamigoWrapper: FC<MetamigoWrapperProps> = ({ path }) => {
|
|||
>
|
||||
<Grid item sx={{ height: "100vh", width: "100%" }}>
|
||||
<Iframe
|
||||
id="link"
|
||||
url={fullMetamigoURL}
|
||||
id="metamigo"
|
||||
url="/proxy/metamigo"
|
||||
width="100%"
|
||||
height="100%"
|
||||
frameBorder={0}
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
"use client";
|
||||
|
||||
import { FC } from "react";
|
||||
import getConfig from "next/config";
|
||||
import { Grid } from "@mui/material";
|
||||
import Iframe from "react-iframe";
|
||||
|
||||
|
|
@ -10,10 +9,7 @@ type LeafcutterWrapperProps = {
|
|||
};
|
||||
|
||||
export const LeafcutterWrapper: FC<LeafcutterWrapperProps> = ({ path }) => {
|
||||
const {
|
||||
publicRuntimeConfig: { linkURL },
|
||||
} = getConfig();
|
||||
const fullLeafcutterURL = `${linkURL}/proxy/leafcutter/${path}`;
|
||||
const leafcutterURL = `https://lc.digiresilience.org/${path}`;
|
||||
|
||||
return (
|
||||
<Grid
|
||||
|
|
@ -25,7 +21,7 @@ export const LeafcutterWrapper: FC<LeafcutterWrapperProps> = ({ path }) => {
|
|||
<Grid item sx={{ height: "100vh", width: "100%" }}>
|
||||
<Iframe
|
||||
id="leafcutter"
|
||||
url={fullLeafcutterURL}
|
||||
url={leafcutterURL}
|
||||
width="100%"
|
||||
height="100%"
|
||||
frameBorder={0}
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ type PageProps = {
|
|||
};
|
||||
|
||||
export default function Page({ params: { view } }: PageProps) {
|
||||
<LeafcutterWrapper path={view} />;
|
||||
return <LeafcutterWrapper path={view} />;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,49 +21,31 @@ const rewriteURL = (request: NextRequestWithAuth, originBaseURL: string, destina
|
|||
|
||||
requestHeaders.delete('connection');
|
||||
|
||||
// console.log({ finalHeaders: requestHeaders });
|
||||
|
||||
return NextResponse.rewrite(new URL(destinationURL), { request: { headers: requestHeaders } });
|
||||
};
|
||||
|
||||
const checkRewrites = async (request: NextRequestWithAuth) => {
|
||||
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 ?? "https://lc.digiresilience.org";
|
||||
const metamigoURL = process.env.METAMIGO_URL ?? "http://metamigo-frontend:3000";
|
||||
|
||||
console.log({ linkBaseURL, zammadURL, leafcutterURL, metamigoURL });
|
||||
const labelStudioURL = process.env.LABEL_STUDIO_URL ?? "http://label-studio:8080";
|
||||
|
||||
if (request.nextUrl.pathname.startsWith('/proxy/leafcutter')) {
|
||||
const headers = { 'X-Leafcutter-Embedded': "true" };
|
||||
return rewriteURL(request, linkBaseURL, leafcutterURL, headers);
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy/leafcutter`, leafcutterURL, headers);
|
||||
} else if (request.nextUrl.pathname.startsWith('/proxy/metamigo')) {
|
||||
return rewriteURL(request, linkBaseURL, metamigoURL);
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy/metamigo`, metamigoURL);
|
||||
} else if (request.nextUrl.pathname.startsWith('/proxy/label-studio')) {
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy/label-studio`, labelStudioURL);
|
||||
} else if (request.nextUrl.pathname.startsWith('/proxy/zammad')) {
|
||||
console.log('proxying to zammad');
|
||||
const { token } = request.nextauth;
|
||||
|
||||
// console.log({ nextauth: request.nextauth });
|
||||
|
||||
const headers = {
|
||||
'X-Forwarded-User': token.email.toLowerCase(),
|
||||
host: 'link-stack-dev.digiresilience.org'
|
||||
};
|
||||
|
||||
// console.log({ headers });
|
||||
|
||||
const headers = { 'X-Forwarded-User': token.email.toLowerCase() };
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy/zammad`, zammadURL, headers);
|
||||
} else if (request.nextUrl.pathname.startsWith('/assets') || request.nextUrl.pathname.startsWith('/api/v1')) {
|
||||
console.log('asset');
|
||||
return rewriteURL(request, linkBaseURL, zammadURL);
|
||||
} else if (request.nextUrl.pathname.startsWith('/proxy/assets')) {
|
||||
console.log('proxy asset');
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy`, zammadURL);
|
||||
} else if (request.nextUrl.pathname.startsWith('/proxy/api')) {
|
||||
console.log('proxy api');
|
||||
return rewriteURL(request, `${linkBaseURL}/proxy`, zammadURL);
|
||||
} else if (request.nextUrl.pathname.startsWith('/api/v1')) {
|
||||
return rewriteURL(request, linkBaseURL, zammadURL);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -77,7 +59,6 @@ export default withAuth(
|
|||
authorized: ({ token, req }) => {
|
||||
const {
|
||||
url,
|
||||
headers,
|
||||
} = req;
|
||||
|
||||
// check login page
|
||||
|
|
|
|||
|
|
@ -11,8 +11,10 @@ const nextConfig = {
|
|||
},
|
||||
publicRuntimeConfig: {
|
||||
linkURL: process.env.LINK_URL ?? "http://localhost:3000",
|
||||
leafcutterURL: process.env.LEAFCUTTER_URL ?? "http://localhost:3001",
|
||||
metamigoURL: process.env.METAMIGO_URL ?? "http://localhost:3002",
|
||||
leafcutterURL:
|
||||
process.env.LEAFCUTTER_URL ?? "https://lc.digiresilience.org",
|
||||
metamigoURL: process.env.METAMIGO_URL ?? "http://localhost:8002",
|
||||
labelStudioURL: process.env.LABEL_STUDIO_URL ?? "http://localhost:8006",
|
||||
muiLicenseKey: process.env.MUI_LICENSE_KEY ?? "",
|
||||
},
|
||||
async rewrites() {
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@
|
|||
"@mui/icons-material": "^5",
|
||||
"@mui/lab": "^5.0.0-alpha.137",
|
||||
"@mui/material": "^5",
|
||||
"@mui/x-data-grid-pro": "^6.10.0",
|
||||
"@mui/x-date-pickers-pro": "^6.10.0",
|
||||
"@mui/x-data-grid-pro": "^6.10.1",
|
||||
"@mui/x-date-pickers-pro": "^6.10.1",
|
||||
"date-fns": "^2.30.0",
|
||||
"graphql-request": "^6.1.0",
|
||||
"material-ui-popup-state": "^5.0.9",
|
||||
"mui-chips-input": "^2.0.2",
|
||||
"next": "13.4.10",
|
||||
"next": "13.4.11",
|
||||
"next-auth": "^4.22.3",
|
||||
"react": "18.2.0",
|
||||
"react-cookie": "^4.1.1",
|
||||
|
|
@ -46,12 +46,12 @@
|
|||
"babel-loader": "^9.1.3",
|
||||
"eslint": "^8.45.0",
|
||||
"eslint-config-airbnb": "^19.0.4",
|
||||
"eslint-config-next": "^13.4.10",
|
||||
"eslint-config-next": "^13.4.11",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-import": "^2.27.5",
|
||||
"eslint-plugin-jsx-a11y": "^6.7.1",
|
||||
"eslint-plugin-prettier": "^5.0.0",
|
||||
"eslint-plugin-react": "^7.32.2",
|
||||
"eslint-plugin-react": "^7.33.0",
|
||||
"typescript": "5.1.6"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
"http-proxy-middleware": "^2.0.6",
|
||||
"jsonwebtoken": "^9.0.1",
|
||||
"jwks-rsa": "^3.0.1",
|
||||
"next": "13.4.10",
|
||||
"next": "13.4.11",
|
||||
"next-auth": "4.22.3",
|
||||
"ra-data-graphql": "^4.12.1",
|
||||
"ra-i18n-polyglot": "^4.12.1",
|
||||
|
|
@ -27,7 +27,7 @@
|
|||
"react-dom": "18.2.0",
|
||||
"react-qr-code": "^2.0.11",
|
||||
"react-redux": "^8.1.1",
|
||||
"react-timer-hook": "^3.0.6",
|
||||
"react-timer-hook": "^3.0.7",
|
||||
"swr": "^2.2.0",
|
||||
"twilio-client": "^1.15.0"
|
||||
},
|
||||
|
|
@ -41,7 +41,7 @@
|
|||
"fmt": "prettier --ignore-path .eslintignore \"**/*.{js,jsx,ts,tsx,graphql,md}\" --write"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@next/eslint-plugin-next": "^13.4.10",
|
||||
"@next/eslint-plugin-next": "^13.4.11",
|
||||
"@types/hapi__wreck": "17.0.1",
|
||||
"@types/react": "18.2.15",
|
||||
"@types/react-mic": "12.4.3",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue