139 lines
4.6 KiB
JavaScript
139 lines
4.6 KiB
JavaScript
|
|
import withBundleAnalyzer from '@next/bundle-analyzer';
|
|
|
|
/** @type {import('next').NextConfig} */
|
|
const nextConfig = {
|
|
output: 'standalone',
|
|
reactStrictMode: true,
|
|
poweredByHeader: false,
|
|
turbopack: {},
|
|
// Server Actions reject request bodies over 1 MB by default, which is smaller than
|
|
// any real photograph, so the admin image uploader needs a raised ceiling. Note that
|
|
// the file is re-sent to the PHP API as a fresh multipart request, so PHP's own
|
|
// `upload_max_filesize` and `post_max_size` have to allow at least this much too,
|
|
// otherwise PHP discards the upload before Laravel can validate it.
|
|
experimental: {
|
|
serverActions: {
|
|
bodySizeLimit: '8mb',
|
|
},
|
|
},
|
|
images: {
|
|
// The logo, the burger button and the social icons are SVGs. Without this
|
|
// flag next/image refuses to optimise them and answers 400, so every SVG
|
|
// in the site silently fails to load. Serving them from the optimiser needs
|
|
// a restrictive CSP on the image endpoint, because an SVG can carry script.
|
|
dangerouslyAllowSVG: true,
|
|
contentDispositionType: 'inline',
|
|
contentSecurityPolicy: "default-src 'self'; script-src 'none'; sandbox;",
|
|
remotePatterns: [
|
|
{
|
|
protocol: 'https',
|
|
hostname: 'via.placeholder.com',
|
|
port: '',
|
|
pathname: '/**',
|
|
},
|
|
{
|
|
protocol: 'https',
|
|
hostname: 'backend.parsaaghayi.ir',
|
|
port: '',
|
|
pathname: '/**',
|
|
},
|
|
{
|
|
protocol: 'https',
|
|
hostname: 'parsaaghayi.ir',
|
|
port: '',
|
|
pathname: '/**',
|
|
},
|
|
],
|
|
},
|
|
async rewrites() {
|
|
return [
|
|
{
|
|
source: '/api/website/:path*',
|
|
destination: `${process.env.NEXT_PUBLIC_BACK_URL}/api/website/:path*`,
|
|
},
|
|
{
|
|
source: '/api/blog/:path*',
|
|
destination: `${process.env.NEXT_PUBLIC_BACK_URL}/api/blog/:path*`,
|
|
},
|
|
];
|
|
},
|
|
async headers() {
|
|
// `upgrade-insecure-requests` is a CSP directive, not a header, so it lives inside
|
|
// the policy value below. `connect-src` allows the production backend only; the dev
|
|
// API runs on plain http://localhost:8000 (see .env.development), so that origin is
|
|
// appended outside of production to keep `next dev` working.
|
|
const connectSrc = ["'self'", 'https://backend.parsaaghayi.ir'];
|
|
if (process.env.NODE_ENV === 'development') {
|
|
connectSrc.push('http://localhost:8000', 'http://127.0.0.1:8000');
|
|
}
|
|
|
|
// TODO follow-up: ship a nonce-based policy (`script-src 'nonce-<random>'` plus
|
|
// `'strict-dynamic'`). `'unsafe-inline'` is still required for scripts because
|
|
// Next.js emits inline bootstrap scripts (hydration payload, next-themes script)
|
|
// and framer-motion/next-themes are not wired up to receive a nonce yet. The nonce
|
|
// can be threaded through the root layout + middleware, which is what lets us drop
|
|
// `'unsafe-inline'` from script-src.
|
|
const contentSecurityPolicy = [
|
|
"default-src 'self'",
|
|
"script-src 'self' 'unsafe-inline'",
|
|
"style-src 'self' 'unsafe-inline'",
|
|
"img-src 'self' data: blob: https:",
|
|
"font-src 'self' data:",
|
|
`connect-src ${connectSrc.join(' ')}`,
|
|
"media-src 'self' blob:",
|
|
"object-src 'none'",
|
|
"base-uri 'self'",
|
|
"frame-ancestors 'none'",
|
|
"form-action 'self'",
|
|
'upgrade-insecure-requests',
|
|
].join('; ');
|
|
|
|
return [
|
|
{
|
|
source: '/:path*',
|
|
headers: [
|
|
{
|
|
key: 'Strict-Transport-Security',
|
|
value: 'max-age=63072000; includeSubDomains; preload',
|
|
},
|
|
{ key: 'X-Content-Type-Options', value: 'nosniff' },
|
|
{ key: 'X-Frame-Options', value: 'DENY' },
|
|
{ key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin' },
|
|
{
|
|
key: 'Permissions-Policy',
|
|
value: 'camera=(), microphone=(), geolocation=(), interest-cohort=()',
|
|
},
|
|
{ key: 'Content-Security-Policy', value: contentSecurityPolicy },
|
|
],
|
|
},
|
|
];
|
|
},
|
|
webpack(config, { isServer }) {
|
|
if (!isServer) {
|
|
config.optimization.splitChunks = {
|
|
chunks: 'all',
|
|
minSize: 30000,
|
|
maxAsyncRequests: 30,
|
|
maxInitialRequests: 30,
|
|
automaticNameDelimiter: '-',
|
|
cacheGroups: {
|
|
vendor: {
|
|
test: /[\\/]node_modules[\\/]/,
|
|
name: 'vendors',
|
|
chunks: 'all',
|
|
},
|
|
},
|
|
};
|
|
}
|
|
return config;
|
|
},
|
|
};
|
|
|
|
const withBundle = withBundleAnalyzer({
|
|
enabled: process.env.ANALYZE === 'true',
|
|
// میتوانید تنظیمات اضافی پلاگین را اینجا اضافه کنید
|
|
})(nextConfig);
|
|
|
|
export default withBundle;
|