-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproxy.ts
More file actions
35 lines (28 loc) · 1.01 KB
/
proxy.ts
File metadata and controls
35 lines (28 loc) · 1.01 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
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
import { trackRegistryDownload } from '@/lib/track'
// Matches component JSONs like /r/button.json, excluding the /r/registry.json
// catalog index that shadcn fetches on init/add.
const REGISTRY_ITEM_PATH = /^\/r\/(?!registry\.json$)[\w-]+\.json$/
export async function proxy(request: NextRequest) {
const pathname = request.nextUrl.pathname
if (REGISTRY_ITEM_PATH.test(pathname)) {
await trackRegistryDownload(request)
}
if (request.nextUrl.searchParams.get('joyco') === '1') {
const response = NextResponse.next()
response.cookies.set('joyco-team', '1', {
maxAge: 60 * 60 * 24 * 365,
path: '/',
sameSite: 'lax',
})
return response
}
if (pathname === '/toolbox/ui' && !request.cookies.has('joyco-team')) {
return NextResponse.redirect(new URL('/', request.url))
}
return NextResponse.next()
}
export const config = {
matcher: '/((?!api|_next/static|_next/image|.*\\.png$).*)',
}