-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
39 lines (35 loc) · 967 Bytes
/
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 {
chain,
nextSafe,
strictDynamic,
reporting,
} from '@next-safe/middleware';
const isDev = process.env.NODE_ENV === 'development';
const reportOnly = !!process.env.CSP_REPORT_ONLY;
const nextSafeMiddleware = nextSafe((req) => {
return {
isDev,
contentSecurityPolicy: {
reportOnly,
'frame-ancestors': 'https://stackblitz.com',
},
// customize as you need: https://trezy.gitbook.io/next-safe/usage/configuration
};
});
const reportingMiddleware = reporting((req) => {
const nextApiReportEndpoint = `/api/reporting`;
return {
csp: {
reportUri: process.env.CSP_REPORT_URI || nextApiReportEndpoint,
},
reportTo: {
max_age: 1800,
endpoints: [
{
url: process.env.REPORT_TO_ENDPOINT_DEFAULT || nextApiReportEndpoint,
},
],
},
};
});
export default chain(nextSafeMiddleware, strictDynamic(), reportingMiddleware);