forked from loo-y/iPhoneOrder.2023
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmiddleware.ts
More file actions
21 lines (18 loc) · 786 Bytes
/
middleware.ts
File metadata and controls
21 lines (18 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import { NextRequest, NextResponse } from 'next/server'
// This function can be marked `async` if using `await` inside
export async function middleware(request: NextRequest) {
console.log(`this.is middleware`, request.body)
// 允许静态html跨域
if(request.method === 'OPTIONS'){
const response = new NextResponse;
console.log(`this.is middleware OPTIONS`, request.body)
response.headers.set("Access-Control-Allow-Origin", "*");
response.headers.set('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
response.headers.set('Access-Control-Allow-Headers', 'Content-Type, Authorization');
return response;
}
}
// See "Matching Paths" below to learn more
export const config = {
matcher: '/api/:path*',
}