feat: add support for selfHosted client-side

This commit is contained in:
swve 2023-03-26 14:04:33 +02:00
parent 316ab4025d
commit 27d2bc08f2
4 changed files with 18 additions and 14 deletions

View file

@ -20,8 +20,8 @@ export default function middleware(req: NextRequest) {
const isSelfHosted = getSelfHostedOption();
const hostname = req.headers.get("host") || "learnhouse.app";
let currentHost = hostname.replace(".localhost:3000", "");
if (!isSelfHosted && currentHost === ("localhost:3000")) {
if (!isSelfHosted && currentHost === "localhost:3000" && !url.pathname.startsWith("/organizations")) {
// Redirect to error page if not self-hosted and on localhost
const errorUrl = "/error";
return NextResponse.redirect(errorUrl, { status: 302 });
@ -33,7 +33,11 @@ export default function middleware(req: NextRequest) {
}
if (url.pathname.startsWith("/organizations")) {
if (!isSelfHosted) {
currentHost = "";
}
url.pathname = url.pathname.replace("/organizations", `/organizations${currentHost}`).replace("localhost:3000", "");
return NextResponse.rewrite(url);
}