forked from David-Parry/sf-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnext.config.ts
More file actions
64 lines (59 loc) · 2.16 KB
/
Copy pathnext.config.ts
File metadata and controls
64 lines (59 loc) · 2.16 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
63
64
import type { NextConfig } from "next";
import { execSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { join } from "node:path";
function git(args: string): string | undefined {
try {
return (
execSync(`git ${args}`, { stdio: ["ignore", "pipe", "ignore"] })
.toString()
.trim() || undefined
);
} catch {
return undefined;
}
}
function packageVersion(): string {
try {
const pkg = JSON.parse(
readFileSync(join(process.cwd(), "package.json"), "utf8"),
);
return typeof pkg.version === "string" ? pkg.version : "0.0.0";
} catch {
return "0.0.0";
}
}
// Incremental build number: CI BUILD_NUMBER when present, else the git commit count (monotonic).
const appVersion = process.env.NEXT_PUBLIC_APP_VERSION ?? packageVersion();
const buildNumber =
process.env.NEXT_PUBLIC_BUILD_NUMBER ??
process.env.BUILD_NUMBER ??
git("rev-list --count HEAD") ??
"0";
const gitSha =
process.env.NEXT_PUBLIC_GIT_SHA ??
process.env.GIT_SHA ??
git("rev-parse --short HEAD") ??
"unknown";
// Note: this app reads and writes through server components and server actions,
// so it needs a Node runtime. `output: "export"` is deliberately not offered.
const nextConfig: NextConfig = {
trailingSlash: true,
// Hosts allowed to load dev-only resources (/_next/hmr, /_next/static…) when the
// dev server is reached from something other than localhost — a phone or another
// machine on the LAN. Matched on hostname alone: ports are ignored, so this has
// nothing to do with the backend's :8000. `localhost` and `**.localhost` are
// already allowed by default; they are listed for the next person reading this.
allowedDevOrigins: ["localhost", "127.0.0.1", "192.168.0.15"],
// `/` is not a page: the app is the contacts manager. A routing-layer redirect
// is a real 308, unlike a prerendered page that would meta-refresh the browser.
async redirects() {
return [{ source: "/", destination: "/contacts", permanent: true }];
},
env: {
NEXT_PUBLIC_APP_VERSION: appVersion,
NEXT_PUBLIC_BUILD_NUMBER: buildNumber,
NEXT_PUBLIC_GIT_SHA: gitSha,
},
};
export default nextConfig;