deploy
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import { dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const nextConfig = {
|
||||
output: "export",
|
||||
trailingSlash: true,
|
||||
output: "standalone",
|
||||
outputFileTracingRoot: __dirname,
|
||||
};
|
||||
|
||||
export default nextConfig;
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"dev": "next dev --hostname 0.0.0.0 --port 3000",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
"build": "next build && node prepare-standalone.mjs",
|
||||
"start": "node start-standalone.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"next": "^15.3.0",
|
||||
|
||||
48
frontend/prepare-standalone.mjs
Normal file
48
frontend/prepare-standalone.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
import { cpSync, existsSync, mkdirSync, readdirSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
|
||||
const standalone = ".next/standalone";
|
||||
const staticSource = ".next/static";
|
||||
const publicSource = "public";
|
||||
|
||||
function copyDir(source, target) {
|
||||
if (!existsSync(source)) {
|
||||
return;
|
||||
}
|
||||
mkdirSync(target, { recursive: true });
|
||||
cpSync(source, target, { recursive: true });
|
||||
}
|
||||
|
||||
function serverDirs() {
|
||||
if (!existsSync(standalone)) {
|
||||
return [];
|
||||
}
|
||||
const dirs = [];
|
||||
if (existsSync(join(standalone, "server.js"))) {
|
||||
dirs.push(standalone);
|
||||
}
|
||||
for (const entry of readdirSync(standalone, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory()) {
|
||||
continue;
|
||||
}
|
||||
const candidate = join(standalone, entry.name);
|
||||
if (existsSync(join(candidate, "server.js"))) {
|
||||
dirs.push(candidate);
|
||||
}
|
||||
}
|
||||
return dirs;
|
||||
}
|
||||
|
||||
for (const dir of serverDirs()) {
|
||||
copyDir(staticSource, join(dir, ".next/static"));
|
||||
copyDir(publicSource, join(dir, "public"));
|
||||
}
|
||||
|
||||
if (!existsSync(join(standalone, "server.js"))) {
|
||||
const nested = serverDirs().find((dir) => dir !== standalone);
|
||||
if (nested) {
|
||||
cpSync(nested, standalone, { recursive: true });
|
||||
copyDir(staticSource, join(standalone, ".next/static"));
|
||||
copyDir(publicSource, join(standalone, "public"));
|
||||
}
|
||||
}
|
||||
23
frontend/start-standalone.mjs
Normal file
23
frontend/start-standalone.mjs
Normal file
@@ -0,0 +1,23 @@
|
||||
import { spawnSync } from "node:child_process";
|
||||
import { existsSync } from "node:fs";
|
||||
|
||||
const candidates = [
|
||||
".next/standalone/server.js",
|
||||
".next/standalone/frontend/server.js",
|
||||
];
|
||||
const server = candidates.find((path) => existsSync(path));
|
||||
|
||||
if (!server) {
|
||||
throw new Error("Next standalone server.js not found; run npm run build first");
|
||||
}
|
||||
|
||||
const result = spawnSync(process.execPath, [server], {
|
||||
stdio: "inherit",
|
||||
env: {
|
||||
...process.env,
|
||||
HOSTNAME: process.env.HOSTNAME || "127.0.0.1",
|
||||
PORT: process.env.PORT || "3000",
|
||||
},
|
||||
});
|
||||
|
||||
process.exit(result.status ?? 1);
|
||||
Reference in New Issue
Block a user