@react-router/serve 0.0.0-experimental-8cee090e4 → 0.0.0-experimental-63fd291ad
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.cjs → bin.js} +2 -5
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +127 -87
- package/package.json +16 -18
package/{bin.cjs → bin.js}
RENAMED
|
@@ -1,10 +1,7 @@
|
|
|
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 it's CJS entry script
|
|
5
5
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
if (error) console.error(error);
|
|
9
|
-
process.exit(1);
|
|
10
|
-
});
|
|
7
|
+
require("./dist/cli");
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { };
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/serve v0.0.0-experimental-
|
|
3
|
+
* @react-router/serve v0.0.0-experimental-63fd291ad
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -9,98 +9,138 @@
|
|
|
9
9
|
*
|
|
10
10
|
* @license MIT
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
"use strict";
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __copyProps = (to, from, except, desc) => {
|
|
20
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
21
|
+
for (let key of __getOwnPropNames(from))
|
|
22
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
23
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
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"));
|
|
24
48
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
49
|
+
import_source_map_support.default.install({
|
|
50
|
+
retrieveSourceMap: function(source) {
|
|
51
|
+
let match = source.startsWith("file://");
|
|
52
|
+
if (match) {
|
|
53
|
+
let filePath = import_node_url.default.fileURLToPath(source);
|
|
54
|
+
let sourceMapPath = `${filePath}.map`;
|
|
55
|
+
if (import_node_fs.default.existsSync(sourceMapPath)) {
|
|
56
|
+
return {
|
|
57
|
+
url: source,
|
|
58
|
+
map: import_node_fs.default.readFileSync(sourceMapPath, "utf8")
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
35
65
|
run();
|
|
36
66
|
function isRSCServerBuild(build) {
|
|
37
|
-
|
|
67
|
+
return Boolean(
|
|
68
|
+
typeof build === "object" && build && "default" in build && typeof build.default === "object" && build.default && "fetch" in build.default && typeof build.default.fetch === "function"
|
|
69
|
+
);
|
|
38
70
|
}
|
|
39
71
|
function parseNumber(raw) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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}`;
|
|
72
|
+
if (raw === void 0) return void 0;
|
|
73
|
+
let maybe = Number(raw);
|
|
74
|
+
if (Number.isNaN(maybe)) return void 0;
|
|
75
|
+
return maybe;
|
|
53
76
|
}
|
|
54
77
|
async function run() {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
78
|
+
let port = parseNumber(process.env.PORT) ?? await (0, import_get_port.default)({ port: 3e3 });
|
|
79
|
+
let buildPathArg = process.argv[2];
|
|
80
|
+
if (!buildPathArg) {
|
|
81
|
+
console.error(`
|
|
59
82
|
Usage: react-router-serve <server-build-path> - e.g. react-router-serve build/server/index.js`);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
let buildPath = import_node_path.default.resolve(buildPathArg);
|
|
86
|
+
let buildModule = await import(import_node_url.default.pathToFileURL(buildPath).href);
|
|
87
|
+
let build;
|
|
88
|
+
let isRSCBuild = false;
|
|
89
|
+
if (isRSCBuild = isRSCServerBuild(buildModule)) {
|
|
90
|
+
const config = {
|
|
91
|
+
publicPath: "/",
|
|
92
|
+
assetsBuildDirectory: import_node_path.default.join("..", "client"),
|
|
93
|
+
...buildModule.unstable_reactRouterServeConfig || {}
|
|
94
|
+
};
|
|
95
|
+
build = {
|
|
96
|
+
fetch: buildModule.default.fetch,
|
|
97
|
+
publicPath: config.publicPath,
|
|
98
|
+
assetsBuildDirectory: import_node_path.default.resolve(
|
|
99
|
+
import_node_path.default.dirname(buildPath),
|
|
100
|
+
config.assetsBuildDirectory
|
|
101
|
+
)
|
|
102
|
+
};
|
|
103
|
+
} else {
|
|
104
|
+
build = buildModule;
|
|
105
|
+
}
|
|
106
|
+
let onListen = () => {
|
|
107
|
+
let address = process.env.HOST || Object.values(import_node_os.default.networkInterfaces()).flat().find((ip) => String(ip?.family).includes("4") && !ip?.internal)?.address;
|
|
108
|
+
if (!address) {
|
|
109
|
+
console.log(`[react-router-serve] http://localhost:${port}`);
|
|
110
|
+
} else {
|
|
111
|
+
console.log(
|
|
112
|
+
`[react-router-serve] http://localhost:${port} (http://${address}:${port})`
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let app = (0, import_express2.default)();
|
|
117
|
+
app.disable("x-powered-by");
|
|
118
|
+
if (!isRSCBuild) {
|
|
119
|
+
app.use((0, import_compression.default)());
|
|
120
|
+
}
|
|
121
|
+
app.use(
|
|
122
|
+
import_node_path.default.posix.join(build.publicPath, "assets"),
|
|
123
|
+
import_express2.default.static(import_node_path.default.join(build.assetsBuildDirectory, "assets"), {
|
|
124
|
+
immutable: true,
|
|
125
|
+
maxAge: "1y"
|
|
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
|
+
});
|
|
104
146
|
}
|
|
105
|
-
//#endregion
|
|
106
|
-
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-router/serve",
|
|
3
|
-
"
|
|
4
|
-
"version": "0.0.0-experimental-8cee090e4",
|
|
3
|
+
"version": "0.0.0-experimental-63fd291ad",
|
|
5
4
|
"description": "Production application server for React Router",
|
|
6
5
|
"bugs": {
|
|
7
6
|
"url": "https://github.com/remix-run/react-router/issues"
|
|
@@ -16,15 +15,15 @@
|
|
|
16
15
|
"./package.json": "./package.json"
|
|
17
16
|
},
|
|
18
17
|
"bin": {
|
|
19
|
-
"react-router-serve": "bin.
|
|
18
|
+
"react-router-serve": "bin.js"
|
|
20
19
|
},
|
|
21
20
|
"wireit": {
|
|
22
21
|
"build": {
|
|
23
|
-
"command": "
|
|
22
|
+
"command": "tsup",
|
|
24
23
|
"files": [
|
|
25
24
|
"../../pnpm-workspace.yaml",
|
|
26
25
|
"*.ts",
|
|
27
|
-
"bin.
|
|
26
|
+
"bin.js",
|
|
28
27
|
"tsconfig.json",
|
|
29
28
|
"package.json"
|
|
30
29
|
],
|
|
@@ -34,34 +33,33 @@
|
|
|
34
33
|
}
|
|
35
34
|
},
|
|
36
35
|
"dependencies": {
|
|
37
|
-
"@
|
|
36
|
+
"@mjackson/node-fetch-server": "^0.2.0",
|
|
38
37
|
"compression": "^1.8.1",
|
|
39
|
-
"express": "^
|
|
40
|
-
"get-port": "
|
|
38
|
+
"express": "^4.19.2",
|
|
39
|
+
"get-port": "5.1.1",
|
|
41
40
|
"morgan": "^1.10.1",
|
|
42
41
|
"source-map-support": "^0.5.21",
|
|
43
|
-
"@react-router/
|
|
44
|
-
"@react-router/
|
|
42
|
+
"@react-router/express": "0.0.0-experimental-63fd291ad",
|
|
43
|
+
"@react-router/node": "0.0.0-experimental-63fd291ad"
|
|
45
44
|
},
|
|
46
45
|
"peerDependencies": {
|
|
47
|
-
"react-router": "0.0.0-experimental-
|
|
46
|
+
"react-router": "0.0.0-experimental-63fd291ad"
|
|
48
47
|
},
|
|
49
48
|
"devDependencies": {
|
|
50
49
|
"@types/compression": "^1.8.1",
|
|
51
|
-
"@types/express": "^
|
|
50
|
+
"@types/express": "^4.17.9",
|
|
52
51
|
"@types/morgan": "^1.9.10",
|
|
53
|
-
"@types/node": "^22.19.19",
|
|
54
52
|
"@types/source-map-support": "^0.5.6",
|
|
55
|
-
"
|
|
56
|
-
"typescript": "^
|
|
57
|
-
"wireit": "0.14.
|
|
53
|
+
"tsup": "^8.3.0",
|
|
54
|
+
"typescript": "^5.4.5",
|
|
55
|
+
"wireit": "0.14.9"
|
|
58
56
|
},
|
|
59
57
|
"engines": {
|
|
60
|
-
"node": ">=
|
|
58
|
+
"node": ">=20.0.0"
|
|
61
59
|
},
|
|
62
60
|
"files": [
|
|
63
61
|
"dist/",
|
|
64
|
-
"bin.
|
|
62
|
+
"bin.js",
|
|
65
63
|
"CHANGELOG.md",
|
|
66
64
|
"LICENSE.md",
|
|
67
65
|
"README.md"
|