@react-router/serve 7.16.0 → 8.0.0-pre.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{bin.js → bin.cjs} +5 -2
- package/dist/cli.d.ts +2 -1
- package/dist/cli.js +87 -127
- package/package.json +18 -16
package/{bin.js → bin.cjs}
RENAMED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// If not already set, default `NODE_ENV=production` so React loads the proper
|
|
4
|
-
// version in
|
|
4
|
+
// version in its CJS entry script
|
|
5
5
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
void import("./dist/cli.js").catch((error) => {
|
|
8
|
+
if (error) console.error(error);
|
|
9
|
+
process.exit(1);
|
|
10
|
+
});
|
package/dist/cli.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
export { };
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/serve
|
|
3
|
+
* @react-router/serve v8.0.0-pre.0
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -9,138 +9,98 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
return to;
|
|
26
|
-
};
|
|
27
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
28
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
29
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
30
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
31
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
32
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
33
|
-
mod
|
|
34
|
-
));
|
|
35
|
-
|
|
36
|
-
// cli.ts
|
|
37
|
-
var import_node_fs = __toESM(require("fs"));
|
|
38
|
-
var import_node_os = __toESM(require("os"));
|
|
39
|
-
var import_node_path = __toESM(require("path"));
|
|
40
|
-
var import_node_url = __toESM(require("url"));
|
|
41
|
-
var import_express = require("@react-router/express");
|
|
42
|
-
var import_node_fetch_server = require("@mjackson/node-fetch-server");
|
|
43
|
-
var import_compression = __toESM(require("compression"));
|
|
44
|
-
var import_express2 = __toESM(require("express"));
|
|
45
|
-
var import_morgan = __toESM(require("morgan"));
|
|
46
|
-
var import_source_map_support = __toESM(require("source-map-support"));
|
|
47
|
-
var import_get_port = __toESM(require("get-port"));
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import os from "node:os";
|
|
14
|
+
import path from "node:path";
|
|
15
|
+
import url from "node:url";
|
|
16
|
+
import { createRequestHandler } from "@react-router/express";
|
|
17
|
+
import { createRequestListener } from "@remix-run/node-fetch-server";
|
|
18
|
+
import compression from "compression";
|
|
19
|
+
import express from "express";
|
|
20
|
+
import morgan from "morgan";
|
|
21
|
+
import sourceMapSupport from "source-map-support";
|
|
22
|
+
import getPort from "get-port";
|
|
23
|
+
//#region cli.ts
|
|
48
24
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
});
|
|
25
|
+
sourceMapSupport.install({ retrieveSourceMap: function(source) {
|
|
26
|
+
if (source.startsWith("file://")) {
|
|
27
|
+
let sourceMapPath = `${url.fileURLToPath(source)}.map`;
|
|
28
|
+
if (fs.existsSync(sourceMapPath)) return {
|
|
29
|
+
url: source,
|
|
30
|
+
map: fs.readFileSync(sourceMapPath, "utf8")
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
} });
|
|
65
35
|
run();
|
|
66
36
|
function isRSCServerBuild(build) {
|
|
67
|
-
|
|
68
|
-
typeof build === "object" && build && "default" in build && typeof build.default === "object" && build.default && "fetch" in build.default && typeof build.default.fetch === "function"
|
|
69
|
-
);
|
|
37
|
+
return Boolean(typeof build === "object" && build && "default" in build && typeof build.default === "object" && build.default && "fetch" in build.default && typeof build.default.fetch === "function");
|
|
70
38
|
}
|
|
71
39
|
function parseNumber(raw) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
40
|
+
if (raw === void 0) return void 0;
|
|
41
|
+
let maybe = Number(raw);
|
|
42
|
+
if (Number.isNaN(maybe)) return void 0;
|
|
43
|
+
return maybe;
|
|
44
|
+
}
|
|
45
|
+
function getExpressPath(publicPath) {
|
|
46
|
+
let pathname;
|
|
47
|
+
try {
|
|
48
|
+
pathname = new URL(publicPath).pathname;
|
|
49
|
+
} catch {
|
|
50
|
+
pathname = publicPath;
|
|
51
|
+
}
|
|
52
|
+
return pathname.startsWith("/") ? pathname : `/${pathname}`;
|
|
76
53
|
}
|
|
77
54
|
async function run() {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
55
|
+
let port = parseNumber(process.env.PORT) ?? await getPort({ port: 3e3 });
|
|
56
|
+
let buildPathArg = process.argv[2];
|
|
57
|
+
if (!buildPathArg) {
|
|
58
|
+
console.error(`
|
|
82
59
|
Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
);
|
|
128
|
-
app.use(build.publicPath, import_express2.default.static(build.assetsBuildDirectory));
|
|
129
|
-
app.use(import_express2.default.static("public", { maxAge: "1h" }));
|
|
130
|
-
app.use((0, import_morgan.default)("tiny"));
|
|
131
|
-
if (build.fetch) {
|
|
132
|
-
app.all("*", (0, import_node_fetch_server.createRequestListener)(build.fetch));
|
|
133
|
-
} else {
|
|
134
|
-
app.all(
|
|
135
|
-
"*",
|
|
136
|
-
(0, import_express.createRequestHandler)({
|
|
137
|
-
build: buildModule,
|
|
138
|
-
mode: process.env.NODE_ENV
|
|
139
|
-
})
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
let server = process.env.HOST ? app.listen(port, process.env.HOST, onListen) : app.listen(port, onListen);
|
|
143
|
-
["SIGTERM", "SIGINT"].forEach((signal) => {
|
|
144
|
-
process.once(signal, () => server?.close(console.error));
|
|
145
|
-
});
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
|
62
|
+
let buildPath = path.resolve(buildPathArg);
|
|
63
|
+
let buildModule = await import(url.pathToFileURL(buildPath).href);
|
|
64
|
+
let build;
|
|
65
|
+
let isRSCBuild = false;
|
|
66
|
+
if (isRSCBuild = isRSCServerBuild(buildModule)) {
|
|
67
|
+
const config = {
|
|
68
|
+
publicPath: "/",
|
|
69
|
+
assetsBuildDirectory: path.join("..", "client"),
|
|
70
|
+
...buildModule.unstable_reactRouterServeConfig || {}
|
|
71
|
+
};
|
|
72
|
+
build = {
|
|
73
|
+
fetch: buildModule.default.fetch,
|
|
74
|
+
publicPath: config.publicPath,
|
|
75
|
+
assetsBuildDirectory: path.resolve(path.dirname(buildPath), config.assetsBuildDirectory)
|
|
76
|
+
};
|
|
77
|
+
} else build = buildModule;
|
|
78
|
+
let onListen = (error) => {
|
|
79
|
+
if (error) throw error;
|
|
80
|
+
let address = process.env.HOST || Object.values(os.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
|
|
81
|
+
if (!address) console.log(`[react-router-serve] http://localhost:${port}`);
|
|
82
|
+
else console.log(`[react-router-serve] http://localhost:${port} (http://${address}:${port})`);
|
|
83
|
+
};
|
|
84
|
+
let app = express();
|
|
85
|
+
app.disable("x-powered-by");
|
|
86
|
+
if (!isRSCBuild) app.use(compression());
|
|
87
|
+
let expressPublicPath = getExpressPath(build.publicPath);
|
|
88
|
+
app.use(path.posix.join(expressPublicPath, "assets"), express.static(path.join(build.assetsBuildDirectory, "assets"), {
|
|
89
|
+
immutable: true,
|
|
90
|
+
maxAge: "1y"
|
|
91
|
+
}));
|
|
92
|
+
app.use(expressPublicPath, express.static(build.assetsBuildDirectory));
|
|
93
|
+
app.use(express.static("public", { maxAge: "1h" }));
|
|
94
|
+
app.use(morgan("tiny"));
|
|
95
|
+
if (build.fetch) app.all("/{*splat}", createRequestListener(build.fetch));
|
|
96
|
+
else app.all("/{*splat}", createRequestHandler({
|
|
97
|
+
build: buildModule,
|
|
98
|
+
mode: process.env.NODE_ENV
|
|
99
|
+
}));
|
|
100
|
+
let server = process.env.HOST ? app.listen(port, process.env.HOST, onListen) : app.listen(port, onListen);
|
|
101
|
+
["SIGTERM", "SIGINT"].forEach((signal) => {
|
|
102
|
+
process.once(signal, () => server?.close(console.error));
|
|
103
|
+
});
|
|
146
104
|
}
|
|
105
|
+
//#endregion
|
|
106
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/serve",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "8.0.0-pre.0",
|
|
4
5
|
"description": "Production application server for React Router",
|
|
5
6
|
"bugs": {
|
|
6
7
|
"url": "https://github.com/remix-run/react-router/issues"
|
|
@@ -15,15 +16,15 @@
|
|
|
15
16
|
"./package.json": "./package.json"
|
|
16
17
|
},
|
|
17
18
|
"bin": {
|
|
18
|
-
"react-router-serve": "bin.
|
|
19
|
+
"react-router-serve": "bin.cjs"
|
|
19
20
|
},
|
|
20
21
|
"wireit": {
|
|
21
22
|
"build": {
|
|
22
|
-
"command": "
|
|
23
|
+
"command": "tsdown",
|
|
23
24
|
"files": [
|
|
24
25
|
"../../pnpm-workspace.yaml",
|
|
25
26
|
"*.ts",
|
|
26
|
-
"bin.
|
|
27
|
+
"bin.cjs",
|
|
27
28
|
"tsconfig.json",
|
|
28
29
|
"package.json"
|
|
29
30
|
],
|
|
@@ -33,33 +34,34 @@
|
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@
|
|
37
|
+
"@remix-run/node-fetch-server": "^0.13.3",
|
|
37
38
|
"compression": "^1.8.1",
|
|
38
|
-
"express": "^
|
|
39
|
-
"get-port": "
|
|
39
|
+
"express": "^5.2.1",
|
|
40
|
+
"get-port": "7.2.0",
|
|
40
41
|
"morgan": "^1.10.1",
|
|
41
42
|
"source-map-support": "^0.5.21",
|
|
42
|
-
"@react-router/express": "
|
|
43
|
-
"@react-router/node": "
|
|
43
|
+
"@react-router/express": "8.0.0-pre.0",
|
|
44
|
+
"@react-router/node": "8.0.0-pre.0"
|
|
44
45
|
},
|
|
45
46
|
"peerDependencies": {
|
|
46
|
-
"react-router": "
|
|
47
|
+
"react-router": "8.0.0-pre.0"
|
|
47
48
|
},
|
|
48
49
|
"devDependencies": {
|
|
49
50
|
"@types/compression": "^1.8.1",
|
|
50
|
-
"@types/express": "^
|
|
51
|
+
"@types/express": "^5.0.6",
|
|
51
52
|
"@types/morgan": "^1.9.10",
|
|
53
|
+
"@types/node": "^22.19.19",
|
|
52
54
|
"@types/source-map-support": "^0.5.6",
|
|
53
|
-
"
|
|
54
|
-
"typescript": "^
|
|
55
|
-
"wireit": "0.14.
|
|
55
|
+
"tsdown": "^0.22.0",
|
|
56
|
+
"typescript": "^6.0.3",
|
|
57
|
+
"wireit": "0.14.12"
|
|
56
58
|
},
|
|
57
59
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
60
|
+
"node": ">=22.12.0"
|
|
59
61
|
},
|
|
60
62
|
"files": [
|
|
61
63
|
"dist/",
|
|
62
|
-
"bin.
|
|
64
|
+
"bin.cjs",
|
|
63
65
|
"CHANGELOG.md",
|
|
64
66
|
"LICENSE.md",
|
|
65
67
|
"README.md"
|