mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
fix: less imports in middleware
This commit is contained in:
parent
ea0b1ea014
commit
6e3f908af5
1 changed files with 6 additions and 3 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { LEARNHOUSE_DOMAIN, getDefaultOrg, getSelfHostedOption } from "./services/config/config";
|
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
export const config = {
|
export const config = {
|
||||||
|
|
@ -15,13 +15,16 @@ export const config = {
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
export default function middleware(req: NextRequest) {
|
export default function middleware(req: NextRequest) {
|
||||||
|
const LEARNHOUSE_DOMAIN = process.env.NEXT_PUBLIC_LEARNHOUSE_DOMAIN;
|
||||||
const url = req.nextUrl;
|
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 hostname = req.headers.get("host") || "learnhouse.app";
|
||||||
|
const defaultOrg = isSelfHosted ? process.env.NEXT_PUBLIC_LEARNHOUSE_DEFAULT_ORG : null;
|
||||||
let currentHost = hostname.replace(`.${LEARNHOUSE_DOMAIN}`, "");
|
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
|
// Redirect to error page if not self-hosted and on localhost
|
||||||
const errorUrl = "/error";
|
const errorUrl = "/error";
|
||||||
return NextResponse.redirect(errorUrl, { status: 302 });
|
return NextResponse.redirect(errorUrl, { status: 302 });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue