-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
119 lines (106 loc) · 3.53 KB
/
Copy pathnext.config.ts
File metadata and controls
119 lines (106 loc) · 3.53 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import type { NextConfig } from 'next';
import { withSentryConfig } from '@sentry/nextjs';
const nextConfig: NextConfig = {
images: {
// unoptimized: true, // Enabled Image Optimization
},
async redirects() {
return [
{
source: '/ecert',
destination: '/certificates',
permanent: true,
},
{
source: '/ecert/:path*',
destination: '/certificates/:path*',
permanent: true,
},
{
source: '/esijil',
destination: '/certificates',
permanent: true,
},
{
source: '/esijil/:path*',
destination: '/certificates/:path*',
permanent: true,
},
];
},
async headers() {
// Security: Content-Security-Policy tuned for KlikForm stack
// (Next.js inline scripts, Google Fonts, Supabase, Sentry, BCL.my)
const cspDirectives = [
`default-src 'self'`,
// Next.js requires unsafe-inline for its runtime scripts & styles
`script-src 'self' 'unsafe-inline' 'unsafe-eval' *.vercel-scripts.com`,
`style-src 'self' 'unsafe-inline' fonts.googleapis.com`,
`font-src 'self' fonts.gstatic.com`,
// Sentry Session Replay spins up a Web Worker from a blob: URL for
// compression. Without an explicit worker-src it falls back to
// script-src (which lacks blob:) and gets blocked.
`worker-src 'self' blob:`,
// Allow images from any HTTPS source (cover images, avatars, etc.)
`img-src 'self' data: blob: https:`,
// Allow connections to Supabase, Sentry tunnel, and BCL.my payment API
`connect-src 'self' *.supabase.co *.supabase.in *.sentry.io wss://*.supabase.co https://bcl.my`,
`frame-ancestors 'none'`,
`base-uri 'self'`,
`form-action 'self'`,
].join('; ');
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: cspDirectives,
},
{
key: 'X-Frame-Options',
value: 'DENY',
},
{
key: 'X-Content-Type-Options',
value: 'nosniff',
},
{
key: 'Referrer-Policy',
value: 'origin-when-cross-origin',
},
{
key: 'Permissions-Policy',
value: 'camera=(), microphone=(), geolocation=()',
},
],
},
];
},
};
const config = withSentryConfig(nextConfig, {
// For all available options, see:
// https://github.com/getsentry/sentry-webpack-plugin#options
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
// Only print logs for uploading source maps in CI
silent: !process.env.CI,
// For all available options, see:
// https://docs.sentry.io/platforms/javascript/guides/nextjs/manual-setup/
// Upload a larger set of source maps for prettier stack traces (increases build time)
widenClientFileUpload: true,
// Route browser requests to Sentry through a Next.js rewrite to circumvent ad-blockers.
tunnelRoute: '/monitoring',
// Hides source maps from generated client bundles
sourcemaps: {
deleteSourcemapsAfterUpload: true,
},
// Don't fail the build if Sentry creds are missing (e.g. in PR previews)
disableLogger: true,
});
// Only wrap with Sentry when DSN + auth token are present.
// Locally / on PR previews without secrets, fall through to vanilla nextConfig.
const shouldEnableSentry = Boolean(
process.env.NEXT_PUBLIC_SENTRY_DSN && process.env.SENTRY_AUTH_TOKEN
);
export default shouldEnableSentry ? config : nextConfig;