mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: add support for selfHosted client-side
This commit is contained in:
parent
316ab4025d
commit
27d2bc08f2
4 changed files with 18 additions and 14 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue