Repository navigation
Expand file tree
/
Copy pathnext.config.ts
More file actions
54 lines (50 loc) · 2.04 KB
/
Copy pathnext.config.ts
File metadata and controls
54 lines (50 loc) · 2.04 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
import type { NextConfig } from "next";
import withSerwistInit from "@serwist/next";
/**
* Static security headers. The dynamic, nonce-based Content-Security-Policy is set in
* `middleware.ts` (a nonce must be generated per request). Together these target
* securityheaders.com Grade A. `Referrer-Policy` is intentionally omitted per project
* requirement — see CLAUDE.md §8.
*/
const securityHeaders = [
{
key: "Strict-Transport-Security",
value: "max-age=63072000; includeSubDomains; preload",
},
{ key: "X-Content-Type-Options", value: "nosniff" },
{ key: "X-Frame-Options", value: "DENY" },
{ key: "X-DNS-Prefetch-Control", value: "on" },
{
key: "Permissions-Policy",
value: "camera=(), microphone=(), geolocation=(), browsing-topics=(), payment=()",
},
];
const nextConfig: NextConfig = {
reactStrictMode: true,
poweredByHeader: false,
// Hide the Next.js dev-tools indicator (the floating dev-only badge). Never shipped to prod.
devIndicators: false,
images: {
remotePatterns: [{ protocol: "https", hostname: "*.supabase.co" }],
},
async headers() {
return [{ source: "/:path*", headers: securityHeaders }];
},
};
const withSerwist = withSerwistInit({
swSrc: "app/sw.ts",
swDest: "public/sw.js",
// Register the SW from our own bundle (components/pwa/register-sw.tsx) instead of an
// injected inline script, so the strict nonce-based CSP isn't violated.
register: false,
// Serwist only builds the service worker for production; disabling in dev avoids
// caching headaches while iterating.
disable: process.env.NODE_ENV === "development",
});
// Serwist builds the SW through a webpack plugin. `next dev --turbopack` doesn't run
// webpack, and Next warns when a webpack config is present without a Turbopack equivalent.
// The SW is dev-disabled anyway, so we only apply the Serwist wrapper outside development
// (production `next build` uses webpack) and hand the Turbopack dev server a clean config.
export default process.env.NODE_ENV === "development"
? nextConfig
: withSerwist(nextConfig);