-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
62 lines (56 loc) · 2.1 KB
/
next.config.ts
File metadata and controls
62 lines (56 loc) · 2.1 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
// next.config.ts
import { PHASE_DEVELOPMENT_SERVER } from "next/constants";
import type { NextConfig } from "next";
import withJsonLd from "./scripts/jsonld/index-plugin";
export default (phase: string) => {
const isDev = phase === PHASE_DEVELOPMENT_SERVER;
const isCI = !!process.env.CI; // Detect if we're running in CI
const rawAllowed = process.env.NEXT_ALLOWED_DEV_ORIGINS;
// In CI, default to localhost for Playwright tests
// In local dev without the var set, just warn instead of crashing
if (isDev && !rawAllowed) {
if (isCI) {
// CI environment - use localhost default for testing
// eslint-disable-next-line no-console
console.log("➡ CI detected: Using default localhost origin for tests");
} else {
// Local dev environment - warn but don't crash
// eslint-disable-next-line no-console
console.warn(
'⚠️ NEXT_ALLOWED_DEV_ORIGINS not set. If you need to access the dev server from other devices, ' +
'set NEXT_ALLOWED_DEV_ORIGINS="http://192.168.1.39:3000" (or your device IP) in .env.local'
);
}
}
// Parse allowed origins, defaulting to localhost in CI
const allowedDevOrigins = rawAllowed
? rawAllowed.split(",").map((s) => s.trim()).filter(Boolean)
: isCI
? ["http://localhost:3000", "http://127.0.0.1:3000"]
: [];
if (isDev && allowedDevOrigins.length > 0) {
// eslint-disable-next-line no-console
console.log("➡ NEXT_ALLOWED_DEV_ORIGINS (parsed):", allowedDevOrigins);
}
const nextConfig: NextConfig & {
allowedDevOrigins?: string[];
experimental?: { serverActions?: { allowedOrigins?: string[] } };
} = {
reactStrictMode: true,
...(isDev && allowedDevOrigins.length > 0 ? { allowedDevOrigins } : {}),
experimental: {
...(isDev && allowedDevOrigins.length > 0
? { serverActions: { allowedOrigins: allowedDevOrigins } }
: {}),
},
webpack(config) {
config.module.rules.push({
test: /\.svg$/i,
issuer: /\.[jt]sx?$/,
use: ["@svgr/webpack"],
});
return config;
},
};
return withJsonLd(nextConfig);
};