-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
36 lines (30 loc) · 1.09 KB
/
middleware.ts
File metadata and controls
36 lines (30 loc) · 1.09 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
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const response = NextResponse.next();
// Add caching headers for static assets
if (request.nextUrl.pathname.startsWith('/_next/static/')) {
response.headers.set('Cache-Control', 'public, max-age=31536000, immutable');
}
// Add caching for equipment images
if (request.nextUrl.pathname.startsWith('/images/equipment/')) {
response.headers.set('Cache-Control', 'public, max-age=3600, stale-while-revalidate=86400');
}
// Fix for Google OAuth callback on port 3001
if (request.nextUrl.pathname.startsWith('/api/auth/callback/google') &&
request.nextUrl.searchParams.has('state') &&
request.nextUrl.port === '3000') {
// Redirect to the same path but on port 3001
const url = request.nextUrl.clone();
url.port = '3001';
return NextResponse.redirect(url);
}
return response;
}
export const config = {
matcher: [
'/_next/static/:path*',
'/images/:path*',
'/api/auth/callback/google',
],
};