buster/web/next.config.mjs

93 lines
2.6 KiB
JavaScript
Raw Normal View History

import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
2025-04-09 23:17:08 +08:00
import withBundleAnalyzer from '@next/bundle-analyzer';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
2025-04-02 02:58:24 +08:00
// Function to create CSP header with dynamic API URLs
const createCspHeader = (isEmbed = false) => {
const apiUrl = process.env.NEXT_PUBLIC_API_URL
? new URL(process.env.NEXT_PUBLIC_API_URL).origin
: '';
const wsUrl = process.env.NEXT_PUBLIC_WEB_SOCKET_URL
? new URL(process.env.NEXT_PUBLIC_WEB_SOCKET_URL).origin
.replace('https', 'wss')
.replace('http', 'ws')
: '';
return [
// Default directives
"default-src 'self'",
// Scripts
"script-src 'self' 'unsafe-inline' 'unsafe-eval' https://vercel.live https://*.vercel.app https://cdn.jsdelivr.net https://*.cloudflareinsights.com",
// Styles
"style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://cdn.jsdelivr.net",
// Images
"img-src 'self' blob: data: https://*.vercel.app https://*.supabase.co",
// Fonts
"font-src 'self' https://fonts.gstatic.com https://cdn.jsdelivr.net",
// Frame ancestors
isEmbed ? `frame-ancestors 'self' *` : "frame-ancestors 'none'",
2025-04-02 03:12:07 +08:00
// Frame sources
"frame-src 'self' https://vercel.live",
2025-04-02 02:58:24 +08:00
// Connect sources for API calls
2025-04-02 03:12:07 +08:00
`connect-src 'self' http://127.0.0.1:* ws://127.0.0.1:* https://*.vercel.app https://*.supabase.co wss://*.supabase.co ${apiUrl} ${wsUrl}`.trim(),
2025-04-02 02:58:24 +08:00
// Media
"media-src 'self'",
// Object
"object-src 'none'",
// Form actions
"form-action 'self'",
// Base URI
"base-uri 'self'",
// Manifest
"manifest-src 'self'"
].join('; ');
};
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: false,
sassOptions: {
includePaths: [path.join(__dirname, 'styles')],
silenceDeprecations: ['legacy-js-api']
},
experimental: {
serverComponentsExternalPackages: [],
instrumentationHook: false,
serverActions: {
bodySizeLimit: '2mb'
}
},
async headers() {
return [
{
source: '/:path*',
headers: [
{
key: 'Content-Security-Policy',
2025-04-02 02:58:24 +08:00
value: createCspHeader(false)
}
]
},
{
source: '/embed/:path*',
headers: [
{
key: 'Content-Security-Policy',
2025-04-02 02:58:24 +08:00
value: createCspHeader(true)
}
]
}
];
}
};
2025-04-09 23:17:08 +08:00
// export default withBundleAnalyzer({
// enabled: process.env.ANALYZE === 'true'
// })(nextConfig);
2025-03-08 07:02:56 +08:00
export default nextConfig;