fix: less imports in middleware

This commit is contained in:
Badr B 2023-04-12 12:42:48 +02:00 committed by GitHub
parent ea0b1ea014
commit 6e3f908af5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 });