-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
85 lines (77 loc) · 2.52 KB
/
Copy pathnext.config.mjs
File metadata and controls
85 lines (77 loc) · 2.52 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
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Helper to get hostname for CSP and Image Remote Patterns
const getHostname = (url) => {
if (!url) return null;
try {
return new URL(url).hostname;
} catch {
return null;
}
};
const apiHostname = getHostname(process.env.NEXT_PUBLIC_API_URL);
const devHostname = "axile-dev-env.onrender.com";
// Combine hostnames for CSP (unique values only)
const trustedHostnames = [...new Set([apiHostname, devHostname].filter(Boolean))].join(' ');
/** @type {import('next').NextConfig} */
const nextConfig = {
// Set explicit Turbopack root to prevent scanning parent directories
turbopack: {
root: __dirname,
},
// Security headers
async headers() {
return [
{
source: "/:path*",
headers: [
{
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=(self), microphone=(self), geolocation=(self)",
},
{
key: "Content-Security-Policy",
value:
`default-src 'self'; script-src 'self' 'unsafe-eval' 'unsafe-inline' https://accounts.google.com https://apis.google.com https://va.vercel-scripts.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com; img-src 'self' data: ${trustedHostnames} https://*.googleusercontent.com https://res.cloudinary.com https://*.cloudinary.com; connect-src 'self' ${trustedHostnames} https://nubapi.com https://accounts.google.com https://va.vercel-scripts.com https://vitals.vercel-insights.com; frame-src https://accounts.google.com;`,
},
],
},
];
},
// Image optimization configuration
images: {
remotePatterns: [
...(apiHostname ? [{ protocol: "https", hostname: apiHostname, pathname: "/**" }] : []),
{
protocol: "https",
hostname: devHostname,
pathname: "/**",
},
{
protocol: "https",
hostname: "*.googleusercontent.com",
pathname: "/**",
},
{
protocol: "https",
hostname: "res.cloudinary.com",
pathname: "/**",
},
],
},
};
export default nextConfig;