@cedarjs/cli 5.0.0-canary.2358 → 5.0.0-canary.2360
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/dist/commands/serve.js +37 -17
- package/package.json +12 -12
package/dist/commands/serve.js
CHANGED
|
@@ -103,25 +103,45 @@ const builder = async (yargs) => {
|
|
|
103
103
|
const webPort = argv.webPort ?? getWebPort();
|
|
104
104
|
const webHost = argv.webHost ?? getWebHost();
|
|
105
105
|
const apiRootPath = argv.apiRootPath ?? "/";
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
const apiTarget = `http://${apiHost.includes(":") ? `[${apiHost}]` : apiHost}:${apiPort}`;
|
|
107
|
+
const { serveStatic } = await import("srvx/static");
|
|
108
|
+
const apiUrl = getConfig().web.apiUrl;
|
|
109
|
+
const webDist = getPaths().web.dist;
|
|
110
|
+
const indexHtml = fs.readFileSync(
|
|
111
|
+
path.join(webDist, "index.html"),
|
|
112
|
+
"utf-8"
|
|
113
|
+
);
|
|
114
|
+
const webServer = serveSrvx({
|
|
115
|
+
// Dummy fetch handler. All requests are handled by middleware
|
|
116
|
+
fetch: async () => new Response("Not Found", { status: 404 }),
|
|
117
|
+
middleware: [
|
|
118
|
+
serveStatic({ dir: webDist }),
|
|
119
|
+
async (req, next) => {
|
|
120
|
+
const url = new URL(req.url, "http://localhost");
|
|
121
|
+
if (!url.pathname.startsWith(apiUrl)) {
|
|
122
|
+
return next();
|
|
123
|
+
}
|
|
124
|
+
const targetPath = url.pathname.slice(apiUrl.length) || "/";
|
|
125
|
+
const root = apiRootPath === "/" ? "" : apiRootPath;
|
|
126
|
+
const targetUrl = `${apiTarget}${root}${targetPath}${url.search}`;
|
|
127
|
+
return fetch(targetUrl, {
|
|
128
|
+
method: req.method,
|
|
129
|
+
headers: req.headers,
|
|
130
|
+
body: req.body
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
() => {
|
|
134
|
+
const headers = { "Content-Type": "text/html" };
|
|
135
|
+
return new Response(indexHtml, { headers });
|
|
136
|
+
}
|
|
137
|
+
],
|
|
122
138
|
port: webPort,
|
|
123
|
-
|
|
139
|
+
hostname: webHost,
|
|
140
|
+
gracefulShutdown: false,
|
|
141
|
+
manual: true
|
|
124
142
|
});
|
|
143
|
+
webServer.serve();
|
|
144
|
+
await webServer.ready();
|
|
125
145
|
console.log(`Web server listening at http://${webHost}:${webPort}`);
|
|
126
146
|
process.stdout.write(
|
|
127
147
|
`API server starting at http://${apiHost}:${apiPort}...`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cedarjs/cli",
|
|
3
|
-
"version": "5.0.0-canary.
|
|
3
|
+
"version": "5.0.0-canary.2360",
|
|
4
4
|
"description": "The CedarJS Command Line",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,17 +33,17 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/parser": "7.29.3",
|
|
35
35
|
"@babel/preset-typescript": "7.28.5",
|
|
36
|
-
"@cedarjs/api-server": "5.0.0-canary.
|
|
37
|
-
"@cedarjs/cli-helpers": "5.0.0-canary.
|
|
38
|
-
"@cedarjs/fastify-web": "5.0.0-canary.
|
|
39
|
-
"@cedarjs/internal": "5.0.0-canary.
|
|
40
|
-
"@cedarjs/prerender": "5.0.0-canary.
|
|
41
|
-
"@cedarjs/project-config": "5.0.0-canary.
|
|
42
|
-
"@cedarjs/structure": "5.0.0-canary.
|
|
43
|
-
"@cedarjs/telemetry": "5.0.0-canary.
|
|
44
|
-
"@cedarjs/utils": "5.0.0-canary.
|
|
45
|
-
"@cedarjs/vite": "5.0.0-canary.
|
|
46
|
-
"@cedarjs/web-server": "5.0.0-canary.
|
|
36
|
+
"@cedarjs/api-server": "5.0.0-canary.2360",
|
|
37
|
+
"@cedarjs/cli-helpers": "5.0.0-canary.2360",
|
|
38
|
+
"@cedarjs/fastify-web": "5.0.0-canary.2360",
|
|
39
|
+
"@cedarjs/internal": "5.0.0-canary.2360",
|
|
40
|
+
"@cedarjs/prerender": "5.0.0-canary.2360",
|
|
41
|
+
"@cedarjs/project-config": "5.0.0-canary.2360",
|
|
42
|
+
"@cedarjs/structure": "5.0.0-canary.2360",
|
|
43
|
+
"@cedarjs/telemetry": "5.0.0-canary.2360",
|
|
44
|
+
"@cedarjs/utils": "5.0.0-canary.2360",
|
|
45
|
+
"@cedarjs/vite": "5.0.0-canary.2360",
|
|
46
|
+
"@cedarjs/web-server": "5.0.0-canary.2360",
|
|
47
47
|
"@listr2/prompt-adapter-enquirer": "4.2.1",
|
|
48
48
|
"@opentelemetry/api": "1.9.0",
|
|
49
49
|
"@opentelemetry/core": "1.30.1",
|