-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.mjs
More file actions
51 lines (44 loc) · 1.18 KB
/
Copy pathnext.config.mjs
File metadata and controls
51 lines (44 loc) · 1.18 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
import os from "node:os";
function normalizeDevOrigin(value) {
const trimmed = value.trim();
if (!trimmed) return null;
if (trimmed.includes("://")) {
try {
return new URL(trimmed).hostname.toLowerCase();
} catch {
return null;
}
}
return trimmed.split(":")[0].toLowerCase();
}
function getDevOrigins() {
const origins = new Set(["localhost", "127.0.0.1"]);
if (process.env.ALLOWED_DEV_ORIGINS) {
for (const entry of process.env.ALLOWED_DEV_ORIGINS.split(",")) {
const normalized = normalizeDevOrigin(entry);
if (normalized) origins.add(normalized);
}
}
for (const interfaces of Object.values(os.networkInterfaces())) {
for (const net of interfaces ?? []) {
if (net.family === "IPv4" && !net.internal) {
origins.add(net.address.toLowerCase());
}
}
}
return [...origins];
}
/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
allowedDevOrigins: getDevOrigins(),
async headers() {
return [
{
source: "/sw.js",
headers: [{ key: "Cache-Control", value: "no-cache, no-store, must-revalidate" }]
}
];
}
};
export default nextConfig;