From b84efd1c610bfb9f4ff84e9a18473c26739fc830 Mon Sep 17 00:00:00 2001 From: Sergey Mankovsky Date: Mon, 2 Sep 2024 12:16:06 +0200 Subject: [PATCH] Refactor getConfig calls --- www/app/(app)/layout.tsx | 3 +-- www/app/layout.tsx | 3 +-- www/app/lib/edgeConfig.ts | 4 +++- www/app/lib/fief.ts | 2 +- www/middleware.ts | 3 +-- www/pages/api/send-zulip-message.ts | 5 ++--- 6 files changed, 9 insertions(+), 11 deletions(-) diff --git a/www/app/(app)/layout.tsx b/www/app/(app)/layout.tsx index 827b11af..da758a97 100644 --- a/www/app/(app)/layout.tsx +++ b/www/app/(app)/layout.tsx @@ -11,8 +11,7 @@ export default async function AppLayout({ }: { children: React.ReactNode; }) { - const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname; - const config = await getConfig(hostname); + const config = await getConfig(); const { requireLogin, privacy, browse, rooms } = config.features; return ( { if (FIEF_AUTHS[url.hostname]) { return FIEF_AUTHS[url.hostname]; } else { - const config = url && (await getConfig(url.hostname)); + const config = url && (await getConfig()); if (config) { FIEF_AUTHS[url.hostname] = new FiefAuth({ client: fiefClient, diff --git a/www/middleware.ts b/www/middleware.ts index 8f29ac55..94ffc176 100644 --- a/www/middleware.ts +++ b/www/middleware.ts @@ -4,8 +4,7 @@ import { getFiefAuthMiddleware } from "./app/lib/fief"; import { getConfig } from "./app/lib/edgeConfig"; export async function middleware(request: NextRequest) { - const hostname = new URL(process.env.NEXT_PUBLIC_SITE_URL!).hostname; - const config = await getConfig(hostname); + const config = await getConfig(); if ( request.nextUrl.pathname.match( diff --git a/www/pages/api/send-zulip-message.ts b/www/pages/api/send-zulip-message.ts index f385b050..2f971241 100644 --- a/www/pages/api/send-zulip-message.ts +++ b/www/pages/api/send-zulip-message.ts @@ -3,9 +3,8 @@ import { URLSearchParams } from "url"; import { getConfig } from "../../app/lib/edgeConfig"; export default async function handler(req, res) { - const domainName = req.headers.host; - const config = await getConfig(domainName); - const { requireLogin, privacy, browse, sendToZulip } = config.features; + const config = await getConfig(); + const { sendToZulip } = config.features; if (req.method === "POST") { const { stream, topic, message } = req.body;