-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
35 lines (28 loc) · 883 Bytes
/
middleware.js
File metadata and controls
35 lines (28 loc) · 883 Bytes
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';
const allowedOrigins = [
'http://localhost:3000',
'https://frammr.no',
'https://reise.frammr.no',
];
export function middleware(req) {
// retrieve the current response
const res = NextResponse.next();
req.headers.get('origin');
if (allowedOrigins.includes(origin)) {
res.headers.append('Access-Control-Allow-Origin', origin);
}
res.headers.append('Access-Control-Allow-Credentials', 'true');
res.headers.append(
'Access-Control-Allow-Methods',
'GET,DELETE,PATCH,POST,PUT',
);
res.headers.append(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
);
return res;
}
// specify the path regex to apply the middleware to
export const config = {
matcher: '/api/departures/:path*',
};