mirror of
https://github.com/rzmk/learnhouse.git
synced 2025-12-19 04:19:25 +00:00
feat: format with prettier
This commit is contained in:
parent
03fb09c3d6
commit
a147ad6610
164 changed files with 11257 additions and 8154 deletions
|
|
@ -1,7 +1,11 @@
|
|||
import { isInstallModeEnabled } from "@services/install/install";
|
||||
import { LEARNHOUSE_DOMAIN, getDefaultOrg, isMultiOrgModeEnabled } from "./services/config/config";
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
import { isInstallModeEnabled } from '@services/install/install'
|
||||
import {
|
||||
LEARNHOUSE_DOMAIN,
|
||||
getDefaultOrg,
|
||||
isMultiOrgModeEnabled,
|
||||
} from './services/config/config'
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
|
|
@ -13,49 +17,51 @@ export const config = {
|
|||
* 4. /examples (inside /public)
|
||||
* 5. all root files inside /public (e.g. /favicon.ico)
|
||||
*/
|
||||
"/((?!api|_next|fonts|examples|[\\w-]+\\.\\w+).*)",
|
||||
'/((?!api|_next|fonts|examples|[\\w-]+\\.\\w+).*)',
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
export default async function middleware(req: NextRequest) {
|
||||
// Get initial data
|
||||
const hosting_mode = isMultiOrgModeEnabled() ? "multi" : "single";
|
||||
const default_org = getDefaultOrg();
|
||||
const pathname = req.nextUrl.pathname;
|
||||
const fullhost = req.headers ? req.headers.get("host") : "";
|
||||
const hosting_mode = isMultiOrgModeEnabled() ? 'multi' : 'single'
|
||||
const default_org = getDefaultOrg()
|
||||
const pathname = req.nextUrl.pathname
|
||||
const fullhost = req.headers ? req.headers.get('host') : ''
|
||||
|
||||
// Organizations & Global settings
|
||||
if (pathname.startsWith("/organizations")) {
|
||||
return NextResponse.rewrite(new URL(pathname, req.url));
|
||||
if (pathname.startsWith('/organizations')) {
|
||||
return NextResponse.rewrite(new URL(pathname, req.url))
|
||||
}
|
||||
|
||||
// Install Page
|
||||
if (pathname.startsWith("/install")) {
|
||||
if (pathname.startsWith('/install')) {
|
||||
// Check if install mode is enabled
|
||||
const install_mode = await isInstallModeEnabled();
|
||||
const install_mode = await isInstallModeEnabled()
|
||||
if (install_mode) {
|
||||
return NextResponse.rewrite(new URL(pathname, req.url));
|
||||
return NextResponse.rewrite(new URL(pathname, req.url))
|
||||
} else {
|
||||
return NextResponse.redirect(new URL("/", req.url));
|
||||
return NextResponse.redirect(new URL('/', req.url))
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic Pages Editor
|
||||
if (pathname.match(/^\/course\/[^/]+\/activity\/[^/]+\/edit$/)) {
|
||||
return NextResponse.rewrite(new URL(`/editor${pathname}`, req.url));
|
||||
return NextResponse.rewrite(new URL(`/editor${pathname}`, req.url))
|
||||
}
|
||||
|
||||
// Multi Organization Mode
|
||||
if (hosting_mode === "multi") {
|
||||
if (hosting_mode === 'multi') {
|
||||
// Get the organization slug from the URL
|
||||
const orgslug = fullhost ? fullhost.replace(`.${LEARNHOUSE_DOMAIN}`, "") : default_org;
|
||||
return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url));
|
||||
const orgslug = fullhost
|
||||
? fullhost.replace(`.${LEARNHOUSE_DOMAIN}`, '')
|
||||
: default_org
|
||||
return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url))
|
||||
}
|
||||
|
||||
// Single Organization Mode
|
||||
if (hosting_mode === "single") {
|
||||
if (hosting_mode === 'single') {
|
||||
// Get the default organization slug
|
||||
const orgslug = default_org;
|
||||
return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url));
|
||||
const orgslug = default_org
|
||||
return NextResponse.rewrite(new URL(`/orgs/${orgslug}${pathname}`, req.url))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue