-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
middleware.ts
39 lines (35 loc) · 1.04 KB
/
middleware.ts
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
// import { kv } from '@vercel/kv'
import { NextFetchEvent, NextResponse } from 'next/server'
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
*/
{
source: '/((?!api|tags|experiments|_next/static|_next/image|favicon.ico).*)',
missing: [
{ type: 'header', key: 'next-router-prefetch' },
{ type: 'header', key: 'purpose', value: 'prefetch' },
],
},
],
}
export default function middleware(request: Request, context: NextFetchEvent) {
const response = NextResponse.next()
// Background inventory update
context.waitUntil(
(async () => {
try {
// comment this because it's starting to get traffic and Vercel is not cheap lol
// await kv.incr('all_views')
} catch (error) {
console.error('Failed to update views:', error)
}
})()
)
return response
}