@workflow/web 5.0.0-beta.57 → 5.0.0-beta.58

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.
Files changed (27) hide show
  1. package/build/client/assets/{arrow-up-right-XpJjI06G.js → arrow-up-right-jHPcOZmb.js} +1 -1
  2. package/build/client/assets/{highlighted-body-B3W2YXNL-DA3N01jE.js → highlighted-body-B3W2YXNL-CBBI0JQ-.js} +1 -1
  3. package/build/client/assets/{home-CLktiGIz.js → home-BcIEUw9E.js} +33 -12
  4. package/build/client/assets/{loader-circle-Cj8CH5bR.js → loader-circle-HeezuKOU.js} +1 -1
  5. package/build/client/assets/{manifest-3ffb4984.js → manifest-a541ae9e.js} +1 -1
  6. package/build/client/assets/{mermaid-3ZIDBTTL-DG0Grjgm.js → mermaid-3ZIDBTTL-ClcCzUqi.js} +62 -8
  7. package/build/client/assets/{root-3gE7cfR2.js → root-DLS5V7HU.js} +3 -3
  8. package/build/client/assets/{run-detail-gOfjBB1S.js → run-detail-DWoMKBqC.js} +37 -11
  9. package/build/client/assets/{workflow-graph-viewer-Cg3Lr_h8.js → workflow-graph-viewer-syfKq6DB.js} +29 -9
  10. package/build/client/assets/{zstd-browser-decoder-CEJ92wdJ.js → zstd-browser-decoder-D2p6f8lN.js} +1 -1
  11. package/build/server/assets/{app-CLgyAdH3.js → app-CEqDw6uM.js} +24156 -13446
  12. package/build/server/assets/{highlighted-body-B3W2YXNL-B8wbEqnx.js → highlighted-body-B3W2YXNL-C2u3JoU4.js} +7 -2
  13. package/build/server/assets/{index-qorbufop.js → index-BG8LHWgA.js} +8 -3
  14. package/build/server/assets/{index-CD3sqsfS.js → index-BrFZB5-R.js} +1 -1
  15. package/build/server/assets/{mermaid-3ZIDBTTL-CDOlxgin.js → mermaid-3ZIDBTTL-BZ2gmvHb.js} +7 -2
  16. package/build/server/assets/{token-BfBe4cAY.js → token-KvMwAySl.js} +1 -1
  17. package/build/server/assets/{token-util-CYhmjL6g.js → token-util-DGBKzRwD.js} +1 -1
  18. package/build/server/assets/{wrapper-CUYQE5_Q.js → wrapper-CBRVXtq2.js} +12 -14
  19. package/build/server/assets/{zstd-browser-decoder-CIXVj9sh.js → zstd-browser-decoder-BxTIaNvq.js} +7 -2
  20. package/build/server/index.js +8 -4
  21. package/handler.js +13 -96
  22. package/package.json +9 -10
  23. package/server.d.ts +5 -1
  24. package/server.js +32 -39
  25. package/static.js +86 -0
  26. package/build/server/assets/websocket-server-DB4GPS66.js +0 -3669
  27. package/build/server/assets/ws-transport-xTHJJcp4.js +0 -551
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { b9 as reactExports, ba as R, bb as Ks, bc as jsxRuntimeExports, bd as Qe } from "./app-CLgyAdH3.js";
5
+ import { b9 as reactExports, ba as R, bb as Ks, bc as jsxRuntimeExports, bd as Qe } from "./app-CEqDw6uM.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
@@ -47,7 +47,12 @@ import "os";
47
47
  import "assert/strict";
48
48
  import "net";
49
49
  import "node:assert/strict";
50
- import "express";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
51
56
  var L = ({ code: s, language: t, raw: e, className: n, ...d$1 }) => {
52
57
  let { shikiTheme: l } = reactExports.useContext(R), o = Ks(), [m, i] = reactExports.useState(e);
53
58
  return reactExports.useEffect(() => {
@@ -2,8 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { H as HookSchema } from "./app-CLgyAdH3.js";
6
- import { A, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, B, s, t, u, v, C, D, w, E, x, y, z, F, G, I, J, K, L, M, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az, aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM, aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ, a_, a$, b0, b1, b2, b3, b4, b5, b6, b7, b8 } from "./app-CLgyAdH3.js";
5
+ import { H as HookSchema } from "./app-CEqDw6uM.js";
6
+ import { A, a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, B, s, t, u, v, C, D, w, E, x, y, z, F, G, I, J, K, L, M, O, P, Q, R, S, T, U, V, W, X, Y, Z, _, $, a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, aa, ab, ac, ad, ae, af, ag, ah, ai, aj, ak, al, am, an, ao, ap, aq, ar, as, at, au, av, aw, ax, ay, az, aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM, aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ, a_, a$, b0, b1, b2, b3, b4, b5, b6, b7, b8 } from "./app-CEqDw6uM.js";
7
7
  import "node:stream";
8
8
  import "stream";
9
9
  import "util";
@@ -48,7 +48,12 @@ import "os";
48
48
  import "assert/strict";
49
49
  import "net";
50
50
  import "node:assert/strict";
51
- import "express";
51
+ import "https";
52
+ import "http";
53
+ import "tls";
54
+ import "url";
55
+ import "zlib";
56
+ import "buffer";
52
57
  export {
53
58
  A as ANALYTICS_EVENTS_GET_MANY_LIMIT,
54
59
  a as ANALYTICS_MAX_ATTRIBUTE_FILTERS,
@@ -1137,7 +1137,7 @@ function requireWebsocket() {
1137
1137
  const DEFAULT_MAX_PAYLOAD = 256 * 1024;
1138
1138
  async function loadWebSocketServer() {
1139
1139
  try {
1140
- const ws = await import("./wrapper-CUYQE5_Q.js");
1140
+ const ws = await import("./wrapper-CBRVXtq2.js");
1141
1141
  return ws.WebSocketServer;
1142
1142
  } catch {
1143
1143
  throw new Error(
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { N as Nt } from "./app-CLgyAdH3.js";
5
+ import { N as Nt } from "./app-CEqDw6uM.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
@@ -47,7 +47,12 @@ import "os";
47
47
  import "assert/strict";
48
48
  import "net";
49
49
  import "node:assert/strict";
50
- import "express";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
51
56
  export {
52
57
  Nt as Mermaid
53
58
  };
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { bx as requireTokenError, bw as requireTokenUtil, bv as getDefaultExportFromCjs } from "./app-CLgyAdH3.js";
5
+ import { bp as requireTokenError, bo as requireTokenUtil, bn as getDefaultExportFromCjs } from "./app-CEqDw6uM.js";
6
6
  function _mergeNamespaces(n, m) {
7
7
  for (var i = 0; i < m.length; i++) {
8
8
  const e = m[i];
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { bv as getDefaultExportFromCjs, bw as requireTokenUtil } from "./app-CLgyAdH3.js";
5
+ import { bn as getDefaultExportFromCjs, bo as requireTokenUtil } from "./app-CEqDw6uM.js";
6
6
  function _mergeNamespaces(n, m) {
7
7
  for (var i = 0; i < m.length; i++) {
8
8
  const e = m[i];
@@ -2,9 +2,8 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { W as WebSocket } from "./websocket-server-DB4GPS66.js";
6
- import { p, r, s, w, a, e, b } from "./websocket-server-DB4GPS66.js";
7
- import "./app-CLgyAdH3.js";
5
+ import { bf as WebSocket } from "./app-CEqDw6uM.js";
6
+ import { bg, bh, bi, bj, bk, bl, bm } from "./app-CEqDw6uM.js";
8
7
  import "node:stream";
9
8
  import "stream";
10
9
  import "util";
@@ -49,21 +48,20 @@ import "os";
49
48
  import "assert/strict";
50
49
  import "net";
51
50
  import "node:assert/strict";
52
- import "express";
53
- import "http";
54
- import "buffer";
55
- import "zlib";
56
51
  import "https";
52
+ import "http";
57
53
  import "tls";
58
54
  import "url";
55
+ import "zlib";
56
+ import "buffer";
59
57
  export {
60
- p as PerMessageDeflate,
61
- r as Receiver,
62
- s as Sender,
58
+ bg as PerMessageDeflate,
59
+ bh as Receiver,
60
+ bi as Sender,
63
61
  WebSocket,
64
- w as WebSocketServer,
65
- a as createWebSocketStream,
62
+ bj as WebSocketServer,
63
+ bk as createWebSocketStream,
66
64
  WebSocket as default,
67
- e as extension,
68
- b as subprotocol
65
+ bl as extension,
66
+ bm as subprotocol
69
67
  };
@@ -2,7 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { be as registerZstdDecoder } from "./app-CLgyAdH3.js";
5
+ import { be as registerZstdDecoder } from "./app-CEqDw6uM.js";
6
6
  import "node:stream";
7
7
  import "stream";
8
8
  import "util";
@@ -47,7 +47,12 @@ import "os";
47
47
  import "assert/strict";
48
48
  import "net";
49
49
  import "node:assert/strict";
50
- import "express";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
51
56
  let registered = false;
52
57
  let modulePromise;
53
58
  function loadWasmModule() {
@@ -2,8 +2,7 @@ import { createRequire as __wkfCreateRequire } from "node:module";
2
2
  if (typeof require === "undefined") {
3
3
  globalThis.require = __wkfCreateRequire(import.meta.url);
4
4
  }
5
- import { bz, bA } from "./assets/app-CLgyAdH3.js";
6
- import "express";
5
+ import { bq } from "./assets/app-CEqDw6uM.js";
7
6
  import "node:stream";
8
7
  import "stream";
9
8
  import "util";
@@ -48,7 +47,12 @@ import "os";
48
47
  import "assert/strict";
49
48
  import "net";
50
49
  import "node:assert/strict";
50
+ import "https";
51
+ import "http";
52
+ import "tls";
53
+ import "url";
54
+ import "zlib";
55
+ import "buffer";
51
56
  export {
52
- bz as app,
53
- bA as createFetchHandler
57
+ bq as createFetchHandler
54
58
  };
package/handler.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Framework-agnostic, in-process entry point for @workflow/web.
3
3
  *
4
- * Unlike `server.js` (which starts a standalone Express HTTP server), this
4
+ * Unlike `server.js` (which starts a standalone HTTP server of its own), this
5
5
  * exports a single Web-standard fetch handler that another server can mount
6
6
  * under an arbitrary base path — e.g. `@workflow/nitro` mounting the dashboard
7
7
  * at `/_workflow` without spawning a second server/port.
@@ -17,41 +17,16 @@
17
17
  */
18
18
 
19
19
  import { existsSync } from 'node:fs';
20
- import { readFile, stat } from 'node:fs/promises';
21
20
  import path from 'node:path';
22
21
  import { fileURLToPath, pathToFileURL } from 'node:url';
23
22
  import { recordDashboard } from './registry.js';
23
+ import { createStaticHandler } from './static.js';
24
24
 
25
25
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
26
26
  const buildDir = path.resolve(__dirname, 'build');
27
27
  const clientDir = path.join(buildDir, 'client');
28
28
  const serverEntry = path.join(buildDir, 'server', 'index.js');
29
29
 
30
- // Minimal extension -> MIME map for serving the static client build. A wrong
31
- // Content-Type on the entry module breaks the whole app, so be explicit.
32
- const MIME_TYPES = {
33
- '.js': 'text/javascript',
34
- '.mjs': 'text/javascript',
35
- '.css': 'text/css',
36
- '.json': 'application/json',
37
- '.map': 'application/json',
38
- '.html': 'text/html',
39
- '.ico': 'image/x-icon',
40
- '.svg': 'image/svg+xml',
41
- '.png': 'image/png',
42
- '.jpg': 'image/jpeg',
43
- '.jpeg': 'image/jpeg',
44
- '.gif': 'image/gif',
45
- '.webp': 'image/webp',
46
- '.avif': 'image/avif',
47
- '.woff': 'font/woff',
48
- '.woff2': 'font/woff2',
49
- '.ttf': 'font/ttf',
50
- '.otf': 'font/otf',
51
- '.txt': 'text/plain',
52
- '.wasm': 'application/wasm',
53
- };
54
-
55
30
  /** Normalize a mount path: `/` or empty -> "" (root); otherwise strip trailing slash. */
56
31
  function normalizeBasename(basename) {
57
32
  if (!basename || basename === '/') return '';
@@ -94,6 +69,16 @@ async function buildHandler(basename) {
94
69
  );
95
70
  }
96
71
  const ssr = mod.createFetchHandler(basename || '/');
72
+ const serveStatic = createStaticHandler({
73
+ dir: clientDir,
74
+ basename,
75
+ // The host owns the connection and may compress the response itself. Even
76
+ // where it doesn't, this runs inside someone else's process — spending its
77
+ // CPU and libuv threads on brotli for what is almost always a localhost
78
+ // dev server is a bad trade. `server.js` leaves compression on, since it
79
+ // can be self-hosted over a real network.
80
+ compress: false,
81
+ });
97
82
 
98
83
  return async (request) => {
99
84
  // Advertise this dashboard so the CLI can defer to it (best-effort, once).
@@ -111,76 +96,8 @@ async function buildHandler(basename) {
111
96
  // ignore — registration must never affect request handling
112
97
  }
113
98
 
114
- const staticResponse = await tryServeStatic(request, basename);
99
+ const staticResponse = await serveStatic(request);
115
100
  if (staticResponse) return staticResponse;
116
101
  return ssr(request);
117
102
  };
118
103
  }
119
-
120
- /**
121
- * Resolve a request to a path-within-the-client-build (relative to `clientDir`),
122
- * stripping `basename` and guarding against traversal. Returns null when the
123
- * request can't map to a client file (so it should fall through to the SSR
124
- * handler) — e.g. the index, a directory, or an out-of-tree path.
125
- */
126
- function resolveClientFile(request, basename) {
127
- if (request.method !== 'GET' && request.method !== 'HEAD') return null;
128
-
129
- let pathname;
130
- try {
131
- pathname = decodeURIComponent(new URL(request.url).pathname);
132
- } catch {
133
- return null;
134
- }
135
-
136
- if (basename) {
137
- if (!pathname.startsWith(`${basename}/`)) return null; // index/other -> SSR
138
- pathname = pathname.slice(basename.length);
139
- }
140
-
141
- const relative = pathname.replace(/^\/+/, '');
142
- if (!relative || relative.endsWith('/')) return null;
143
-
144
- const filePath = path.join(clientDir, relative);
145
- // Guard against path traversal escaping the client build directory.
146
- if (filePath !== clientDir && !filePath.startsWith(clientDir + path.sep)) {
147
- return null;
148
- }
149
- return { filePath, relative };
150
- }
151
-
152
- /**
153
- * Serve a file from the prebuilt client bundle if the request maps to one;
154
- * otherwise return null so the request falls through to the SSR handler.
155
- */
156
- async function tryServeStatic(request, basename) {
157
- const resolved = resolveClientFile(request, basename);
158
- if (!resolved) return null;
159
- const { filePath, relative } = resolved;
160
-
161
- let stats;
162
- try {
163
- stats = await stat(filePath);
164
- } catch {
165
- return null;
166
- }
167
- if (!stats.isFile()) return null;
168
-
169
- const ext = path.extname(filePath).toLowerCase();
170
- const headers = new Headers({
171
- 'Content-Type': MIME_TYPES[ext] ?? 'application/octet-stream',
172
- // Hashed assets are content-addressed and safe to cache forever; other
173
- // client files (e.g. favicon) get a short cache.
174
- 'Cache-Control': relative.startsWith('assets/')
175
- ? 'public, max-age=31536000, immutable'
176
- : 'public, max-age=3600',
177
- });
178
-
179
- if (request.method === 'HEAD') {
180
- headers.set('Content-Length', String(stats.size));
181
- return new Response(null, { status: 200, headers });
182
- }
183
-
184
- const body = await readFile(filePath);
185
- return new Response(body, { status: 200, headers });
186
- }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@workflow/web",
3
3
  "description": "Workflow Observability UI",
4
- "version": "5.0.0-beta.57",
4
+ "version": "5.0.0-beta.58",
5
5
  "type": "module",
6
6
  "private": false,
7
7
  "files": [
@@ -12,6 +12,7 @@
12
12
  "handler.d.ts",
13
13
  "registry.js",
14
14
  "registry.d.ts",
15
+ "static.js",
15
16
  "package.json"
16
17
  ],
17
18
  "exports": {
@@ -39,8 +40,8 @@
39
40
  "directory": "packages/web"
40
41
  },
41
42
  "dependencies": {
42
- "@workflow/world-local": "5.0.0-beta.48",
43
- "express": "^5.2.1",
43
+ "@workflow/world-local": "5.0.0-beta.49",
44
+ "srvx": "^0.12.4",
44
45
  "swr": "^2.3.6"
45
46
  },
46
47
  "devDependencies": {
@@ -56,21 +57,19 @@
56
57
  "@radix-ui/react-tabs": "^1.1.13",
57
58
  "@radix-ui/react-tooltip": "1.2.8",
58
59
  "@react-router/dev": "7.13.1",
59
- "@react-router/express": "7.13.1",
60
60
  "@react-router/node": "7.13.1",
61
61
  "@tailwindcss/vite": "4",
62
62
  "@testing-library/react": "^16.3.0",
63
- "@types/express": "^5",
64
63
  "@types/node": "22.19.0",
65
64
  "@types/react": "19",
66
65
  "@types/react-dom": "19",
67
66
  "@vercel/react-router": "1.2.6",
68
- "@workflow/core": "5.0.0-beta.57",
69
- "@workflow/errors": "5.0.0-beta.24",
67
+ "@workflow/core": "5.0.0-beta.58",
68
+ "@workflow/errors": "5.0.0-beta.25",
70
69
  "@workflow/utils": "5.0.0-beta.10",
71
- "@workflow/web-shared": "5.0.0-beta.57",
72
- "@workflow/world": "5.0.0-beta.39",
73
- "@workflow/world-vercel": "5.0.0-beta.52",
70
+ "@workflow/web-shared": "5.0.0-beta.58",
71
+ "@workflow/world": "5.0.0-beta.40",
72
+ "@workflow/world-vercel": "5.0.0-beta.53",
74
73
  "@xyflow/react": "12.10.1",
75
74
  "cbor-x": "^1",
76
75
  "class-variance-authority": "0.7.1",
package/server.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- import type { Server } from 'node:http';
1
+ import type { Server } from 'srvx';
2
2
 
3
+ /**
4
+ * Start the standalone observability UI server on `port` (defaults to `PORT`, then 3000),
5
+ * and resolve once it is listening.
6
+ */
3
7
  export function startServer(port?: number): Promise<Server>;
package/server.js CHANGED
@@ -10,57 +10,50 @@
10
10
 
11
11
  import path from 'node:path';
12
12
  import { fileURLToPath, pathToFileURL } from 'node:url';
13
- import express from 'express';
13
+ import { serve } from 'srvx';
14
+ import { createStaticHandler } from './static.js';
14
15
 
15
16
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
17
  const buildDir = path.resolve(__dirname, 'build');
17
-
18
- async function createApp() {
19
- // Import the compiled server build, which exports { app } (an Express app
20
- // with the React Router request handler already mounted by server/app.ts)
21
- const { app } = await import(
22
- pathToFileURL(path.join(buildDir, 'server/index.js')).href
23
- );
24
-
25
- // Add static file serving in front of the React Router handler.
26
- // We create a wrapper app so static middleware runs first.
27
- const server = express();
28
-
29
- // Serve immutable assets with long-lived cache
30
- server.use(
31
- '/assets',
32
- express.static(path.join(buildDir, 'client/assets'), {
33
- immutable: true,
34
- maxAge: '1y',
35
- })
36
- );
37
-
38
- // Serve static client files with short cache
39
- server.use(express.static(path.join(buildDir, 'client'), { maxAge: '1h' }));
40
-
41
- // Mount the React Router app
42
- server.use(app);
43
-
44
- return server;
45
- }
18
+ const clientDir = path.join(buildDir, 'client');
19
+ const serverEntry = path.join(buildDir, 'server', 'index.js');
46
20
 
47
21
  /**
48
22
  * Start the production HTTP server.
49
23
  *
50
24
  * @param {number} [port] - Port to listen on. Defaults to PORT env or 3000.
51
- * @returns {Promise<import("http").Server>} The HTTP server instance.
25
+ * @returns {Promise<import("srvx").Server>} The listening server. The
26
+ * underlying Node `http.Server` remains reachable via `server.node.server`.
52
27
  */
53
28
  export async function startServer(port) {
54
- const resolvedPort = port ?? parseInt(process.env.PORT || '3000', 10);
55
- const app = await createApp();
29
+ // Import the compiled server build, which exports `createFetchHandler` (the
30
+ // React Router request handler, as a Web `Request` -> `Response` function).
31
+ const { createFetchHandler } = await import(pathToFileURL(serverEntry).href);
32
+
33
+ // Static assets are resolved before the SSR handler ever runs. Compression is
34
+ // left on here (unlike the embedded handler): this server can be self-hosted
35
+ // over a real network, where trading CPU for bytes is worth it.
36
+ const serveStatic = createStaticHandler({ dir: clientDir });
37
+ const ssr = createFetchHandler('/');
56
38
 
57
- return new Promise((resolve, reject) => {
58
- const server = app.listen(resolvedPort, () => {
59
- console.log(`@workflow/web server listening on port ${resolvedPort}`);
60
- resolve(server);
61
- });
62
- server.on('error', reject);
39
+ const server = serve({
40
+ port: port ?? parseInt(process.env.PORT || '3000', 10),
41
+ async fetch(request) {
42
+ return (await serveStatic(request)) ?? ssr(request);
43
+ },
44
+ // Safety net — prevents an unhandled error from taking down the server when
45
+ // the React Router error boundary cannot render (e.g. during SSR).
46
+ error(error) {
47
+ console.error('Unhandled request error:', error);
48
+ return new Response('Internal Server Error', { status: 500 });
49
+ },
50
+ // We print our own listening line below.
51
+ silent: true,
63
52
  });
53
+
54
+ await server.ready();
55
+ console.log(`@workflow/web server listening on ${server.url}`);
56
+ return server;
64
57
  }
65
58
 
66
59
  // When run directly, start the server
package/static.js ADDED
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Static file serving for the prebuilt client bundle (`build/client`), shared
3
+ * by both ways @workflow/web is served:
4
+ *
5
+ * - `server.js` — the standalone server, mounted at the root.
6
+ * - `handler.js` — the embedded handler, mounted under a base path inside
7
+ * another server.
8
+ *
9
+ * Internal: this file ships in the package (both consumers import it
10
+ * relatively) but is deliberately absent from the `exports` map, so it is not
11
+ * part of the public API.
12
+ */
13
+
14
+ import { staticMiddleware } from 'srvx/static';
15
+
16
+ const ONE_YEAR_SECONDS = 31_536_000;
17
+ const ONE_HOUR_SECONDS = 3600;
18
+
19
+ /**
20
+ * Sentinel handed to `staticMiddleware` as its `next()`. Returned by identity
21
+ * when no file matched, so a miss is distinguishable from a real 404 the
22
+ * middleware itself produced. Never sent to a client.
23
+ */
24
+ const MISS = new Response(null, { status: 404 });
25
+
26
+ /**
27
+ * Build a static file handler for `dir`.
28
+ *
29
+ * Two middlewares over the same directory, differing only in freshness policy:
30
+ * everything under `/assets/` is content-hashed by Vite (its URL changes when
31
+ * its bytes do) and can be cached indefinitely without revalidation, while the
32
+ * rest — `favicon.ico` and anything else copied from `public/` — keeps a stable
33
+ * URL and so gets a short lifetime. Both emit ETag/Last-Modified validators
34
+ * regardless, so a stale client revalidates into a 304 rather than a full body.
35
+ *
36
+ * @param {object} options
37
+ * @param {string} options.dir - Directory to serve from (the client build).
38
+ * @param {string} [options.basename] - Mount prefix to strip before resolving,
39
+ * already normalized (no trailing slash; `""` for the root).
40
+ * @param {boolean} [options.compress] - Compress compressible bodies on the
41
+ * fly. Defaults to true.
42
+ * @returns {(request: Request) => Promise<Response | null>} The response, or
43
+ * `null` when the request maps to no file and should fall through to SSR.
44
+ */
45
+ export function createStaticHandler({ dir, basename = '', compress = true }) {
46
+ const hashedAssets = staticMiddleware({
47
+ dir,
48
+ maxAge: ONE_YEAR_SECONDS,
49
+ immutable: true,
50
+ compress,
51
+ });
52
+ const publicFiles = staticMiddleware({
53
+ dir,
54
+ maxAge: ONE_HOUR_SECONDS,
55
+ compress,
56
+ });
57
+
58
+ return async (request) => {
59
+ // Everything else (including the index) is the SSR handler's.
60
+ if (request.method !== 'GET' && request.method !== 'HEAD') return null;
61
+
62
+ let url;
63
+ try {
64
+ url = new URL(request.url);
65
+ } catch {
66
+ return null;
67
+ }
68
+
69
+ let target = request;
70
+ if (basename) {
71
+ // A request at exactly `basename` is the dashboard index, not a file.
72
+ if (!url.pathname.startsWith(`${basename}/`)) return null;
73
+ url.pathname = url.pathname.slice(basename.length);
74
+ // `staticMiddleware` resolves against the request's own pathname, so the
75
+ // mount prefix has to come off the URL rather than be passed alongside.
76
+ // Safe to rebuild for GET/HEAD, which carry no body.
77
+ target = new Request(url, request);
78
+ }
79
+
80
+ const middleware = url.pathname.startsWith('/assets/')
81
+ ? hashedAssets
82
+ : publicFiles;
83
+ const response = await middleware(target, () => MISS);
84
+ return response === MISS ? null : response;
85
+ };
86
+ }