-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
44 lines (38 loc) · 1.27 KB
/
Copy pathproxy.ts
File metadata and controls
44 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { type NextRequest } from 'next/server'
import { NextResponse } from 'next/server'
import { updateSession } from '@/lib/supabase/middleware'
const DISABLED_ADMIN_PREVIEW_PATHS = new Set([
'/admin/automations',
'/admin/branches',
'/admin/course-store',
'/admin/groups',
'/admin/learning-paths',
'/admin/skills',
])
export async function proxy(request: NextRequest) {
const canonicalBase = (process.env.BASE_URL || '').trim().replace(/\/$/, '')
const host =
request.headers.get('x-forwarded-host')?.split(',')[0]?.trim() ||
request.headers.get('host')?.split(',')[0]?.trim() ||
''
if (DISABLED_ADMIN_PREVIEW_PATHS.has(request.nextUrl.pathname)) {
const redirectUrl = request.nextUrl.clone()
redirectUrl.pathname = '/admin'
redirectUrl.search = ''
return NextResponse.redirect(redirectUrl, 307)
}
if (
canonicalBase &&
host &&
/\.vercel\.app$/i.test(host)
) {
const redirectUrl = new URL(request.nextUrl.pathname + request.nextUrl.search, canonicalBase)
return NextResponse.redirect(redirectUrl, 308)
}
return await updateSession(request)
}
export const config = {
matcher: [
'/((?!_next/static|_next/image|favicon.ico|robots.txt|sitemap.xml|.*\\.(?:svg|png|jpg|jpeg|gif|webp|ico|css|js|map)$).*)',
],
}