From 6e3f908af5aa6d6b80604c6fa0a97c714d1dbb8f Mon Sep 17 00:00:00 2001 From: Badr B Date: Wed, 12 Apr 2023 12:42:48 +0200 Subject: [PATCH] fix: less imports in middleware --- front/middleware.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/front/middleware.ts b/front/middleware.ts index f78c3cf4..c4071df0 100644 --- a/front/middleware.ts +++ b/front/middleware.ts @@ -1,4 +1,4 @@ -import { LEARNHOUSE_DOMAIN, getDefaultOrg, getSelfHostedOption } from "./services/config/config"; + import { NextRequest, NextResponse } from "next/server"; export const config = { @@ -15,13 +15,16 @@ export const config = { ], }; + export default function middleware(req: NextRequest) { + const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN; const url = req.nextUrl; - const isSelfHosted = getSelfHostedOption(); + const isSelfHosted = process.env.NEXT_PUBLIC_LEARNHOUSE_SELF_HOSTED === "true" ? true : false const hostname = req.headers.get("host") || "learnhouse.app"; + const defaultOrg = isSelfHosted ? process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG : null; let currentHost = hostname.replace(`.${LEARNHOUSE_DOMAIN}`, ""); - if (!isSelfHosted && currentHost === "localhost:3000" && !url.pathname.startsWith("/organizations")) { + if (!isSelfHosted && currentHost === LEARNHOUSE_DOMAIN && !url.pathname.startsWith("/organizations")) { // Redirect to error page if not self-hosted and on localhost const errorUrl = "/error"; return NextResponse.redirect(errorUrl, { status: 302 });