This commit is contained in:
Darren Clarke 2024-03-16 12:51:56 +01:00
parent c095fa7042
commit 43bfdaa1e3
186 changed files with 276 additions and 37155 deletions

View file

@ -6,5 +6,10 @@ export const metadata: Metadata = {
};
export default function Page() {
return <Home />;
return (
<iframe src="/opensearch/app/dashboards?security_tenant=global#/view/722b74f0-b882-11e8-a6d9-e546fe2bba5f?embed=true&_g=(filters%3A!()%2CrefreshInterval%3A(pause%3A!f%2Cvalue%3A900000)%2Ctime%3A(from%3Anow-7d%2Cto%3Anow))&hide-filter-bar=true"
height="1000"
width="1200"
></iframe>
);
}

View file

@ -0,0 +1,66 @@
import { createProxyMiddleware } from "http-proxy-middleware";
import { NextApiRequest, NextApiResponse } from "next";
import { getToken } from "next-auth/jwt";
/*
if (validDomains.includes(domain)) {
res.headers.set("Access-Control-Allow-Origin", origin);
res.headers.set("Access-Control-Allow-Methods", "GET, POST, OPTIONS");
res.headers.set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
}
*/
const withAuthInfo =
(handler: any) => async (req: NextApiRequest, res: NextApiResponse) => {
const session: any = await getToken({
req,
secret: process.env.NEXTAUTH_SECRET,
});
let email = session?.email?.toLowerCase();
const requestSignature = req.query.signature;
const url = new URL(req.headers.referer as string);
const referrerSignature = url.searchParams.get("signature");
console.log({ requestSignature, referrerSignature });
const isAppPath = !!req.url?.startsWith("/app");
const isResourcePath = !!req.url?.match(/\/(api|app|bootstrap|3961|ui|translations|internal|login|node_modules)/);
if (requestSignature && isAppPath) {
console.log("Has Signature");
}
if (referrerSignature && isResourcePath) {
console.log("Has Signature");
}
if (!email) {
return res.status(401).json({ error: "Not authorized" });
}
req.headers["x-proxy-user"] = email;
req.headers["x-proxy-roles"] = "leafcutter_user";
const auth = `${email}:${process.env.OPENSEARCH_USER_PASSWORD}`;
const buff = Buffer.from(auth);
const base64data = buff.toString("base64");
req.headers.Authorization = `Basic ${base64data}`;
return handler(req, res);
};
const proxy = createProxyMiddleware({
target: process.env.OPENSEARCH_DASHBOARDS_URL,
changeOrigin: true,
xfwd: true,
});
export default withAuthInfo(proxy);
export const config = {
api: {
bodyParser: false,
externalResolver: true,
},
};

View file

@ -24,12 +24,37 @@ const rewriteURL = (request: NextRequestWithAuth, originBaseURL: string, destina
const checkRewrites = async (request: NextRequestWithAuth) => {
const linkBaseURL = process.env.LINK_URL ?? "http://localhost:3000";
const zammadURL = process.env.ZAMMAD_URL ?? "http://zammad-nginx:8080";
const opensearchURL = process.env.OPENSEARCH_URL ?? "http://macmini:5601";
const metamigoURL = process.env.METAMIGO_URL ?? "http://metamigo-api:3000";
const labelStudioURL = process.env.LABEL_STUDIO_URL ?? "http://label-studio:8080";
const { token } = request.nextauth;
const headers = { 'X-Forwarded-User': token?.email?.toLowerCase() };
console.log ({ pathname: request.nextUrl.pathname});
if (request.nextUrl.pathname.startsWith('/metamigo')) {
if (request.nextUrl.pathname.startsWith('/api/v1/configuration/account') ||
request.nextUrl.pathname.startsWith('/api/v1/restapiinfo') ||
request.nextUrl.pathname.startsWith('/api/v1/auth') ||
request.nextUrl.pathname.startsWith('/api/core') ||
request.nextUrl.pathname.startsWith('/api/dataconnections') ||
request.nextUrl.pathname.startsWith('/api/v1/multitenancy') ||
request.nextUrl.pathname.startsWith('/api/ism') ||
request.nextUrl.pathname.startsWith('/node_modules') ||
request.nextUrl.pathname.startsWith('/translations') || request.nextUrl.pathname.startsWith('/6867') || request.nextUrl.pathname.startsWith('/ui') || request.nextUrl.pathname.startsWith('/bootstrap')) {
const headers = {
'x-proxy-user': "admin",
'x-proxy-roles': "all_access",
// 'X-Forwarded-For': "link"
};
return rewriteURL(request, `${linkBaseURL}`, opensearchURL, headers);
}
else if (request.nextUrl.pathname.startsWith('/opensearch')) {
const headers = {
'x-proxy-user': "admin",
'x-proxy-roles': "all_access",
// 'X-Forwarded-For': "link"
};
return rewriteURL(request, `${linkBaseURL}/opensearch`, opensearchURL, headers);
}else if (request.nextUrl.pathname.startsWith('/metamigo')) {
return rewriteURL(request, `${linkBaseURL}/metamigo`, metamigoURL);
} else if (request.nextUrl.pathname.startsWith('/label-studio')) {
return rewriteURL(request, `${linkBaseURL}/label-studio`, labelStudioURL);
@ -83,4 +108,3 @@ export const config = {
'/((?!ws|wss|_next/static|_next/image|favicon.ico).*)',
],
};

View file

@ -15,29 +15,29 @@
"@emotion/react": "^11.11.4",
"@emotion/server": "^11.11.0",
"@emotion/styled": "^11.11.0",
"@fontsource/playfair-display": "^5.0.21",
"@fontsource/playfair-display": "^5.0.23",
"@fontsource/poppins": "^5.0.12",
"@fontsource/roboto": "^5.0.12",
"@mui/icons-material": "^5",
"@mui/lab": "^5.0.0-alpha.167",
"@mui/lab": "^5.0.0-alpha.168",
"@mui/material": "^5",
"@mui/x-data-grid-pro": "^6.19.6",
"@mui/x-date-pickers-pro": "^6.19.6",
"@mui/x-date-pickers-pro": "^6.19.7",
"cryptr": "^6.3.0",
"date-fns": "^3.3.1",
"date-fns": "^3.5.0",
"graphql-request": "^6.1.0",
"leafcutter-common": "*",
"material-ui-popup-state": "^5.0.10",
"mui-chips-input": "^2.1.4",
"next": "14.1.2",
"next-auth": "^4.24.6",
"next": "14.1.3",
"next-auth": "^4.24.7",
"ra-data-graphql": "^4.16.12",
"ra-i18n-polyglot": "^4.16.12",
"ra-input-rich-text": "^4.16.12",
"ra-input-rich-text": "^4.16.13",
"ra-language-english": "^4.16.12",
"ra-postgraphile": "^6.1.2",
"react": "18.2.0",
"react-admin": "^4.16.12",
"react-admin": "^4.16.13",
"react-cookie": "^7.1.0",
"react-digit-input": "^2.1.0",
"react-dom": "18.2.0",
@ -52,18 +52,18 @@
},
"devDependencies": {
"@babel/core": "^7.24.0",
"@types/node": "^20.11.24",
"@types/react": "18.2.63",
"@types/node": "^20.11.28",
"@types/react": "18.2.66",
"@types/uuid": "^9.0.8",
"babel-loader": "^9.1.3",
"eslint": "^8.57.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-next": "^14.1.2",
"eslint-config-next": "^14.1.3",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-react": "^7.34.0",
"typescript": "5.3.3"
"eslint-plugin-react": "^7.34.1",
"typescript": "5.4.2"
}
}