From df9b8abf150e6994bdcaf3f6077af28216832a30 Mon Sep 17 00:00:00 2001 From: Darren Clarke Date: Tue, 30 May 2023 09:05:40 +0000 Subject: [PATCH] Use NextJS middleware for proxying --- apps/leafcutter/components/Question.tsx | 1 - apps/leafcutter/next.config.js | 6 +- apps/leafcutter/pages/faq.tsx | 4 +- .../link/components/InternalZammadWrapper.tsx | 21 ++++--- apps/link/components/LeafcutterWrapper.tsx | 6 +- apps/link/components/MetamigoWrapper.tsx | 41 +++++++++++++ apps/link/middleware.ts | 42 ++++++++++++- apps/link/next.config.js | 9 +-- apps/link/pages/_app.tsx | 2 +- apps/link/pages/api/proxy/[[...path]].ts | 39 ------------ docker/zammad/setup.rb | 10 +++ package-lock.json | 6 +- package.json | 61 ++++++++++--------- 13 files changed, 154 insertions(+), 94 deletions(-) create mode 100644 apps/link/components/MetamigoWrapper.tsx delete mode 100644 apps/link/pages/api/proxy/[[...path]].ts diff --git a/apps/leafcutter/components/Question.tsx b/apps/leafcutter/components/Question.tsx index 9393cb5..50af2a9 100644 --- a/apps/leafcutter/components/Question.tsx +++ b/apps/leafcutter/components/Question.tsx @@ -68,7 +68,6 @@ export const Question: FC = ({ question, answer }) => { {answer} diff --git a/apps/leafcutter/next.config.js b/apps/leafcutter/next.config.js index 3aaa53f..d88693b 100644 --- a/apps/leafcutter/next.config.js +++ b/apps/leafcutter/next.config.js @@ -2,17 +2,19 @@ module.exports = { publicRuntimeConfig: { embedded: Boolean(process.env.LINK_EMBEDDED), }, + basePath: "/proxy/leafcutter", + assetPrefix: "/proxy/leafcutter", i18n: { locales: ["en", "fr"], defaultLocale: "en", }, - rewrites: async () => ({ + /* rewrites: async () => ({ fallback: [ { source: "/:path*", destination: "/api/proxy/:path*", }, ], - }), + }) */ }; diff --git a/apps/leafcutter/pages/faq.tsx b/apps/leafcutter/pages/faq.tsx index 71f0188..79181ba 100644 --- a/apps/leafcutter/pages/faq.tsx +++ b/apps/leafcutter/pages/faq.tsx @@ -31,6 +31,7 @@ const FAQ = () => { question: t("whatCanYouDoWithLeafcutterQuestion"), answer: t("whatCanYouDoWithLeafcutterAnswer"), }, + { question: t("whereIsTheDataComingFromQuestion"), answer: t("whereIsTheDataComingFromAnswer"), @@ -43,6 +44,7 @@ const FAQ = () => { question: t("howDoWeKeepTheDataSafeQuestion"), answer: t("howDoWeKeepTheDataSafeAnswer"), }, + { question: t("howLongDoYouKeepTheDataQuestion"), answer: t("howLongDoYouKeepTheDataAnswer"), @@ -94,7 +96,7 @@ const FAQ = () => { - {questions.map((q, index) => ( + {questions.map((q: any, index: number) => ( ))} diff --git a/apps/link/components/InternalZammadWrapper.tsx b/apps/link/components/InternalZammadWrapper.tsx index faef7df..e1c96f9 100644 --- a/apps/link/components/InternalZammadWrapper.tsx +++ b/apps/link/components/InternalZammadWrapper.tsx @@ -1,4 +1,5 @@ import { FC, useState } from "react"; +import getConfig from "next/config"; import { useRouter } from "next/router"; import Iframe from "react-iframe"; @@ -13,13 +14,16 @@ export const InternalZammadWrapper: FC = ({ }) => { const router = useRouter(); const [display, setDisplay] = useState("none"); - const url = `${origin}/zammad${path}`; - console.log({ origin, path, url }); + const { + publicRuntimeConfig: { linkURL }, + } = getConfig(); + const url = `${linkURL}/proxy/zammad${path}`; + console.log({ url }); return ( // @ts-ignore