@ecopages/core 0.2.0-rc.8 → 0.2.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.
Files changed (216) hide show
  1. package/README.md +39 -38
  2. package/package.json +22 -152
  3. package/src/adapters/README.md +11 -3
  4. package/src/adapters/abstract/application-adapter.d.ts +32 -36
  5. package/src/adapters/abstract/application-adapter.js +61 -47
  6. package/src/adapters/abstract/server-adapter.d.ts +14 -0
  7. package/src/adapters/abstract/server-adapter.js +10 -0
  8. package/src/adapters/abstract/ws-pattern-matcher.d.ts +0 -5
  9. package/src/adapters/abstract/ws-pattern-matcher.js +0 -9
  10. package/src/adapters/bun/create-app.d.ts +12 -16
  11. package/src/adapters/bun/create-app.js +25 -55
  12. package/src/adapters/bun/hmr-manager.d.ts +0 -1
  13. package/src/adapters/bun/hmr-manager.js +2 -4
  14. package/src/adapters/bun/server-adapter.d.ts +15 -21
  15. package/src/adapters/bun/server-adapter.js +33 -67
  16. package/src/adapters/bun/static-preview-host.d.ts +1 -0
  17. package/src/adapters/bun/static-preview-host.js +1 -1
  18. package/src/adapters/create-app.d.ts +63 -8
  19. package/src/adapters/create-app.js +62 -5
  20. package/src/adapters/node/create-app.d.ts +8 -12
  21. package/src/adapters/node/create-app.js +22 -14
  22. package/src/adapters/node/runtime-host.d.ts +10 -10
  23. package/src/adapters/node/runtime-host.js +13 -8
  24. package/src/adapters/node/server-adapter-dependencies.d.ts +2 -10
  25. package/src/adapters/node/server-adapter-dependencies.js +8 -13
  26. package/src/adapters/node/server-adapter.d.ts +30 -32
  27. package/src/adapters/node/server-adapter.js +59 -65
  28. package/src/adapters/shared/hmr/shared-hmr-manager.d.ts +0 -4
  29. package/src/adapters/shared/hmr/shared-hmr-manager.js +0 -12
  30. package/src/adapters/shared/http/api-request-pipeline.d.ts +27 -1
  31. package/src/adapters/shared/http/api-request-pipeline.js +31 -16
  32. package/src/adapters/shared/http/explicit-static-route-matcher.js +5 -2
  33. package/src/adapters/shared/http/fs-server-response-factory.d.ts +2 -9
  34. package/src/adapters/shared/http/fs-server-response-factory.js +5 -33
  35. package/src/adapters/shared/http/fs-server-response-matcher.d.ts +24 -24
  36. package/src/adapters/shared/http/fs-server-response-matcher.js +59 -83
  37. package/src/adapters/shared/runtime/application-adapter.d.ts +1 -0
  38. package/src/adapters/shared/runtime/application-adapter.js +12 -0
  39. package/src/adapters/shared/runtime/bind-runtime-server.d.ts +17 -0
  40. package/src/adapters/shared/runtime/bind-runtime-server.js +50 -0
  41. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.d.ts +1 -3
  42. package/src/adapters/shared/runtime/collect-dev-prewarm-plan.js +1 -4
  43. package/src/adapters/shared/runtime/port-manager-default-prompt.d.ts +6 -0
  44. package/src/adapters/shared/runtime/port-manager-default-prompt.js +41 -0
  45. package/src/adapters/shared/runtime/port-manager.d.ts +3 -3
  46. package/src/adapters/shared/runtime/port-manager.js +14 -45
  47. package/src/adapters/shared/runtime/runtime-app-bootstrap.d.ts +0 -10
  48. package/src/adapters/shared/runtime/runtime-app-bootstrap.js +0 -7
  49. package/src/adapters/shared/runtime/runtime-host.d.ts +5 -2
  50. package/src/adapters/shared/runtime/runtime-server-lifecycle.d.ts +1 -1
  51. package/src/adapters/shared/runtime/runtime-server-lifecycle.js +1 -1
  52. package/src/adapters/shared/runtime/server-adapter.d.ts +26 -5
  53. package/src/adapters/shared/runtime/server-adapter.js +35 -8
  54. package/src/adapters/shared/runtime/server-route-handler.js +11 -3
  55. package/src/adapters/shared/runtime/server-static-builder.d.ts +9 -3
  56. package/src/adapters/shared/runtime/server-static-builder.js +59 -37
  57. package/src/adapters/shared/ws/node-http-websocket-upgrades.d.ts +9 -1
  58. package/src/adapters/shared/ws/node-http-websocket-upgrades.js +8 -2
  59. package/src/build/README.md +12 -8
  60. package/src/build/cache/cache-constants.d.ts +0 -2
  61. package/src/build/cache/cache-constants.js +0 -2
  62. package/src/build/cache/cache-keys.d.ts +0 -2
  63. package/src/build/cache/cache-keys.js +0 -2
  64. package/src/build/cache/output-imports.d.ts +35 -0
  65. package/src/build/cache/output-imports.js +87 -0
  66. package/src/build/cache/pages-unified-graph-build.d.ts +15 -1
  67. package/src/build/cache/pages-unified-graph-build.js +73 -22
  68. package/src/build/cache/production-build-cache.d.ts +2 -2
  69. package/src/build/cache/production-build-cache.js +2 -2
  70. package/src/build/cache/server-entry-build-cache.d.ts +25 -3
  71. package/src/build/cache/server-entry-build-cache.js +129 -13
  72. package/src/build/contracts/build-contracts.d.ts +1 -13
  73. package/src/build/rolldown/runtime-build-output-normalizer.js +3 -6
  74. package/src/build/runtime/build-request-identity.d.ts +2 -6
  75. package/src/build/runtime/build-request-identity.js +2 -8
  76. package/src/build/runtime/build-request-policy.js +1 -1
  77. package/src/build/runtime/deduping-build-executor.d.ts +0 -1
  78. package/src/build/runtime/deduping-build-executor.js +0 -1
  79. package/src/build/server-bundle-publication.d.ts +14 -0
  80. package/src/build/server-bundle-publication.js +49 -0
  81. package/src/cache/index.d.ts +1 -1
  82. package/src/cache/index.js +1 -1
  83. package/src/cache/module-parse-cache.d.ts +2 -29
  84. package/src/cache/module-parse-cache.js +6 -39
  85. package/src/config/README.md +17 -2
  86. package/src/config/apply-user-config.d.ts +8 -0
  87. package/src/config/apply-user-config.js +68 -0
  88. package/src/config/config-builder.d.ts +11 -1
  89. package/src/config/config-builder.js +53 -12
  90. package/src/config/constants.d.ts +4 -4
  91. package/src/config/constants.js +4 -4
  92. package/src/config/define-config.d.ts +9 -0
  93. package/src/config/define-config.js +10 -0
  94. package/src/config/index.d.ts +5 -0
  95. package/src/config/index.js +4 -0
  96. package/src/config/is-finalized-app-config.d.ts +6 -0
  97. package/src/config/is-finalized-app-config.js +11 -0
  98. package/src/config/load-eco-config.d.ts +21 -0
  99. package/src/config/load-eco-config.js +107 -0
  100. package/src/config/resolve-eco-config-path.d.ts +32 -0
  101. package/src/config/resolve-eco-config-path.js +58 -0
  102. package/src/config/server-config-bundle.d.ts +25 -0
  103. package/src/config/server-config-bundle.js +148 -0
  104. package/src/config/user-config-types.d.ts +170 -0
  105. package/src/config/user-config-types.js +1 -0
  106. package/src/dev/README.md +4 -0
  107. package/src/dev/development-restart-watch-paths.d.ts +13 -0
  108. package/src/dev/development-restart-watch-paths.js +37 -0
  109. package/src/dev/development-restart.d.ts +13 -0
  110. package/src/dev/development-restart.js +21 -0
  111. package/src/dev/host-runtime.d.ts +0 -1
  112. package/src/dev/host-runtime.js +0 -3
  113. package/src/dev/sc-server.d.ts +4 -1
  114. package/src/dev/sc-server.js +11 -20
  115. package/src/dev/transform-server/dev-transform-import-rewriter.js +2 -2
  116. package/src/eco/eco.js +4 -0
  117. package/src/errors/http-error-page-contract.d.ts +77 -0
  118. package/src/errors/http-error-page-contract.js +106 -0
  119. package/src/hmr/hmr-file-change-prep.d.ts +0 -1
  120. package/src/hmr/hmr-file-change-prep.js +2 -5
  121. package/src/hmr/hmr-strategy.d.ts +3 -8
  122. package/src/hmr/hmr-strategy.js +3 -8
  123. package/src/index.browser.d.ts +1 -2
  124. package/src/index.browser.js +1 -2
  125. package/src/index.d.ts +5 -6
  126. package/src/index.js +5 -6
  127. package/src/islands/island-host.d.ts +0 -9
  128. package/src/islands/island-host.js +1 -13
  129. package/src/plugins/component-import-discovery.js +2 -2
  130. package/src/plugins/eco-component-meta-plugin.js +5 -5
  131. package/src/plugins/integration-plugin.d.ts +0 -1
  132. package/src/plugins/integration-plugin.js +0 -4
  133. package/src/plugins/processor.d.ts +6 -2
  134. package/src/route-renderer/README.md +4 -0
  135. package/src/{adapters/shared/http/explicit-static-render-preparation.d.ts → route-renderer/explicit-view-render-preparation.d.ts} +3 -3
  136. package/src/route-renderer/orchestration/custom-element-scripts/README.md +2 -2
  137. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.d.ts +14 -2
  138. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-script-preloader.js +12 -5
  139. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.d.ts +8 -0
  140. package/src/route-renderer/orchestration/custom-element-scripts/custom-element-server-module-importer.js +19 -0
  141. package/src/route-renderer/orchestration/document-shell/document-shell-render.service.js +1 -4
  142. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.d.ts +25 -24
  143. package/src/route-renderer/orchestration/foreign-child/foreign-subtree-execution.service.js +18 -20
  144. package/src/route-renderer/orchestration/integration-renderer.d.ts +24 -7
  145. package/src/route-renderer/orchestration/integration-renderer.js +44 -33
  146. package/src/route-renderer/orchestration/integration-renderer.test-fixtures.js +1 -1
  147. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.d.ts +1 -1
  148. package/src/route-renderer/orchestration/page-browser-graph/page-browser-graph-session.js +1 -1
  149. package/src/route-renderer/route-renderer.d.ts +9 -0
  150. package/src/route-renderer/route-renderer.js +18 -0
  151. package/src/services/README.md +2 -1
  152. package/src/services/assets/browser-bundle.service.d.ts +1 -6
  153. package/src/services/error-pages/README.md +9 -0
  154. package/src/services/error-pages/default-error-pages.d.ts +39 -0
  155. package/src/services/error-pages/default-error-pages.js +199 -0
  156. package/src/services/error-pages/error-page-renderer.d.ts +58 -0
  157. package/src/services/error-pages/error-page-renderer.js +146 -0
  158. package/src/services/error-pages/semantic-error-page-exporter.d.ts +23 -0
  159. package/src/services/error-pages/semantic-error-page-exporter.js +35 -0
  160. package/src/services/html/html-rewriter.d.ts +77 -0
  161. package/src/services/html/html-rewriter.js +751 -0
  162. package/src/services/html/html-rewriter.parity.test.bun.d.ts +1 -0
  163. package/src/services/html/html-rewriter.parity.test.bun.js +74 -0
  164. package/src/services/html/html-transformer.service.d.ts +29 -42
  165. package/src/services/html/html-transformer.service.js +85 -157
  166. package/src/services/invalidation/development-invalidation.service.d.ts +9 -20
  167. package/src/services/invalidation/development-invalidation.service.js +26 -39
  168. package/src/services/module-loading/README.md +20 -15
  169. package/src/services/module-loading/app-module-loader.service.d.ts +0 -2
  170. package/src/services/module-loading/app-server-module-transpiler.service.d.ts +1 -1
  171. package/src/services/module-loading/app-server-module-transpiler.service.js +2 -10
  172. package/src/services/module-loading/collection-server-module-build.service.d.ts +0 -1
  173. package/src/services/module-loading/collection-server-module-build.service.js +0 -3
  174. package/src/services/module-loading/host-module-loader-registry.d.ts +0 -1
  175. package/src/services/module-loading/host-module-loader-registry.js +0 -3
  176. package/src/services/module-loading/route-module-build-cache-registry.d.ts +0 -4
  177. package/src/services/module-loading/route-module-build-cache-registry.js +0 -4
  178. package/src/services/module-loading/route-module-build-cache.store.d.ts +8 -0
  179. package/src/services/module-loading/route-module-build-cache.store.js +25 -7
  180. package/src/services/module-loading/route-module-build-manifest.d.ts +12 -1
  181. package/src/services/module-loading/route-module-build-manifest.js +7 -3
  182. package/src/services/module-loading/route-module-dependency-hasher.d.ts +3 -2
  183. package/src/services/module-loading/route-module-dependency-hasher.js +13 -1
  184. package/src/services/module-loading/server-module-transpiler.service.d.ts +1 -15
  185. package/src/services/module-loading/server-module-transpiler.service.js +0 -24
  186. package/src/services/module-loading/view-module-loader.d.ts +10 -0
  187. package/src/services/module-loading/view-module-loader.js +46 -0
  188. package/src/services/runtime-state/entrypoint-dependency-graph.service.js +0 -12
  189. package/src/services/runtime-state/server-invalidation-state.service.d.ts +4 -2
  190. package/src/services/runtime-state/server-invalidation-state.service.js +7 -14
  191. package/src/static-site-generator/README.md +12 -8
  192. package/src/static-site-generator/static-site-generator.d.ts +3 -2
  193. package/src/static-site-generator/static-site-generator.js +17 -3
  194. package/src/types/internal-types.d.ts +1 -38
  195. package/src/types/public-types.d.ts +28 -130
  196. package/src/watchers/project-watcher.d.ts +9 -16
  197. package/src/watchers/project-watcher.js +35 -28
  198. package/src/watchers/project-watcher.test-helpers.d.ts +10 -1
  199. package/src/watchers/project-watcher.test-helpers.js +12 -0
  200. package/src/adapters/abstract/router-adapter.d.ts +0 -26
  201. package/src/adapters/abstract/router-adapter.js +0 -13
  202. package/src/adapters/bun/index.d.ts +0 -2
  203. package/src/adapters/bun/index.js +0 -2
  204. package/src/adapters/index.d.ts +0 -2
  205. package/src/adapters/index.js +0 -2
  206. package/src/eco/eco.utils.d.ts +0 -1
  207. package/src/eco/eco.utils.js +0 -1
  208. package/src/services/cache/index.d.ts +0 -9
  209. package/src/services/cache/index.js +0 -8
  210. package/src/services/html/html-rewriter-provider.service.d.ts +0 -40
  211. package/src/services/html/html-rewriter-provider.service.js +0 -68
  212. package/src/services/module-loading/route-module-build-cache.d.ts +0 -4
  213. package/src/services/module-loading/route-module-build-cache.js +0 -3
  214. package/src/services/runtime-state/dev-graph.service.d.ts +0 -118
  215. package/src/services/runtime-state/dev-graph.service.js +0 -170
  216. /package/src/{adapters/shared/http/explicit-static-render-preparation.js → route-renderer/explicit-view-render-preparation.js} +0 -0
@@ -39,7 +39,7 @@ export interface PortManagerOptions {
39
39
  warn?: (message: string) => void;
40
40
  /** Infers a free port to display in the prompt. Defaults to {@link isPortAvailable}. */
41
41
  probePort?: (port: number) => Promise<boolean>;
42
- /** Custom prompter. Defaults to a readline-based yes/no prompt on the process stdio. */
42
+ /** Custom prompter. Defaults to a Clack confirm on interactive stdio. */
43
43
  prompt?: PromptFunction;
44
44
  /** Enables the prompt flow at all. Defaults to `process.stdin.isTTY && process.stdout.isTTY`. */
45
45
  interactive?: boolean;
@@ -64,7 +64,7 @@ export interface BindPortOptions {
64
64
  allowPortFallback: boolean;
65
65
  }
66
66
  /**
67
- * Owns preview-port assignment: probing, race-release retries, fallback, and
67
+ * Owns server-port assignment: probing, race-release retries, fallback, and
68
68
  * an optional interactive auto-approve prompt.
69
69
  *
70
70
  * @remarks
@@ -83,7 +83,7 @@ export declare class PortManager {
83
83
  private readonly releaseRaceDelayMs;
84
84
  constructor(options: PortManagerOptions);
85
85
  /**
86
- * Binds the preview server to the preferred port.
86
+ * Binds a server to the preferred port.
87
87
  *
88
88
  * @remarks
89
89
  * When the preferred port is free, binds it directly — no prompt, no
@@ -1,5 +1,5 @@
1
1
  import { createServer as createNetServer } from 'node:net';
2
- import { createInterface } from 'node:readline';
2
+ import { createClackDefaultPrompt } from './port-manager-default-prompt.js';
3
3
  /**
4
4
  * Detects whether a thrown error indicates the requested port is already in
5
5
  * use.
@@ -53,42 +53,12 @@ export function isPortAvailable(port, hostname = '127.0.0.1') {
53
53
  tester.listen(port, hostname);
54
54
  });
55
55
  }
56
- function createDefaultPrompt(stdin, stdout) {
57
- return async (message, timeoutMs) => {
58
- stdout.write(`${message} `);
59
- return await new Promise((resolve) => {
60
- const rl = createInterface({ input: stdin, output: undefined, terminal: false });
61
- let settled = false;
62
- const finish = (value) => {
63
- if (settled) {
64
- return;
65
- }
66
- settled = true;
67
- clearTimeout(timer);
68
- rl.close();
69
- stdout.write('\n');
70
- resolve(value);
71
- };
72
- const timer = setTimeout(() => finish(true), timeoutMs);
73
- rl.once('line', (line) => {
74
- const answer = line.trim().toLowerCase();
75
- if (answer === '' || answer === 'y' || answer === 'yes') {
76
- finish(true);
77
- }
78
- else {
79
- finish(false);
80
- }
81
- });
82
- rl.once('close', () => finish(true));
83
- });
84
- };
85
- }
86
- const PREVIEW_PORT_RELEASE_RACE_RETRIES = 2;
87
- const PREVIEW_PORT_FALLBACK_ATTEMPTS = 20;
88
- const PREVIEW_PORT_RELEASE_RACE_DELAY_MS = 100;
89
- const PREVIEW_PORT_AUTO_APPROVE_MS = 10_000;
56
+ const PORT_RELEASE_RACE_RETRIES = 2;
57
+ const PORT_FALLBACK_ATTEMPTS = 20;
58
+ const PORT_RELEASE_RACE_DELAY_MS = 100;
59
+ const PORT_AUTO_APPROVE_MS = 10_000;
90
60
  /**
91
- * Owns preview-port assignment: probing, race-release retries, fallback, and
61
+ * Owns server-port assignment: probing, race-release retries, fallback, and
92
62
  * an optional interactive auto-approve prompt.
93
63
  *
94
64
  * @remarks
@@ -109,10 +79,10 @@ export class PortManager {
109
79
  this.startOnPort = options.startOnPort;
110
80
  this.warn = options.warn;
111
81
  this.probePort = options.probePort ?? isPortAvailable;
112
- this.maxPortOffset = options.maxPortOffset ?? PREVIEW_PORT_FALLBACK_ATTEMPTS - 1;
113
- this.releaseRaceRetries = options.releaseRaceRetries ?? PREVIEW_PORT_RELEASE_RACE_RETRIES;
114
- this.releaseRaceDelayMs = options.releaseRaceDelayMs ?? PREVIEW_PORT_RELEASE_RACE_DELAY_MS;
115
- this.autoApproveMs = options.autoApproveMs ?? PREVIEW_PORT_AUTO_APPROVE_MS;
82
+ this.maxPortOffset = options.maxPortOffset ?? PORT_FALLBACK_ATTEMPTS - 1;
83
+ this.releaseRaceRetries = options.releaseRaceRetries ?? PORT_RELEASE_RACE_RETRIES;
84
+ this.releaseRaceDelayMs = options.releaseRaceDelayMs ?? PORT_RELEASE_RACE_DELAY_MS;
85
+ this.autoApproveMs = options.autoApproveMs ?? PORT_AUTO_APPROVE_MS;
116
86
  this.interactive =
117
87
  typeof options.interactive === 'boolean'
118
88
  ? options.interactive
@@ -121,14 +91,14 @@ export class PortManager {
121
91
  this.prompt = options.prompt;
122
92
  }
123
93
  else if (this.interactive) {
124
- this.prompt = createDefaultPrompt(process.stdin, process.stdout);
94
+ this.prompt = createClackDefaultPrompt();
125
95
  }
126
96
  else {
127
97
  this.prompt = undefined;
128
98
  }
129
99
  }
130
100
  /**
131
- * Binds the preview server to the preferred port.
101
+ * Binds a server to the preferred port.
132
102
  *
133
103
  * @remarks
134
104
  * When the preferred port is free, binds it directly — no prompt, no
@@ -149,7 +119,6 @@ export class PortManager {
149
119
  if (firstAttempt.status === 'factory-refused') {
150
120
  return null;
151
121
  }
152
- // firstAttempt.status === 'port-in-use'
153
122
  await this.shouldFallback(preferredPort, options.allowPortFallback, firstAttempt.error);
154
123
  return await this.fallForward(preferredPort);
155
124
  }
@@ -158,7 +127,7 @@ export class PortManager {
158
127
  const nextFree = await this.findNextFreePort(preferredPort);
159
128
  const nextFreeSuffix = typeof nextFree === 'number' ? ` (next free: ${nextFree})` : '';
160
129
  const autoApproveHint = `auto-yes in ${Math.round(this.autoApproveMs / 1000)}s`;
161
- const message = `[@ecopages/core] Port ${preferredPort} is already in use${nextFreeSuffix}. Bind there instead? [Y/n] (${autoApproveHint})`;
130
+ const message = `Port ${preferredPort} is already in use${nextFreeSuffix}. Bind to the next free port instead? (${autoApproveHint})`;
162
131
  const accepted = await this.prompt(message, this.autoApproveMs);
163
132
  if (!accepted) {
164
133
  throw error;
@@ -174,7 +143,7 @@ export class PortManager {
174
143
  const candidatePort = preferredPort + offset;
175
144
  const attempt = await this.tryPort(candidatePort);
176
145
  if (attempt.status === 'bound') {
177
- this.warn?.(`Port ${preferredPort} is in use; preview serving on port ${attempt.boundPort} instead. Pin the preview port with --port or ECOPAGES_PORT when a fixed binding is required.`);
146
+ this.warn?.(`Port ${preferredPort} is in use; serving on port ${attempt.boundPort} instead. Pin the port with --port or ECOPAGES_PORT when a fixed binding is required.`);
178
147
  return attempt.boundPort;
179
148
  }
180
149
  }
@@ -1,17 +1,11 @@
1
1
  import type { ReturnParseCliArgs } from '../../../utils/parse-cli-args.js';
2
- import type { EcoPagesAppConfig } from '../../../types/internal-types.js';
3
2
  export type RuntimeBinding = {
4
- preferredPort: number;
5
- preferredHostname: string;
6
3
  runtimeOrigin: string;
7
4
  serveOptions: Record<string, unknown>;
8
5
  watch: boolean;
9
6
  /** Whether preview may bind to the next free port when the preferred port is busy. */
10
7
  allowPortFallback: boolean;
11
8
  };
12
- export type StaticRuntimeMode = {
13
- canBuildWithoutRuntimeServer: boolean;
14
- };
15
9
  export declare function resolveServeRuntimeOrigin(serveOptions: {
16
10
  hostname?: string;
17
11
  port?: number | string;
@@ -21,7 +15,3 @@ export declare function resolveRuntimeBinding(options: {
21
15
  serverOptions?: Record<string, unknown>;
22
16
  env?: NodeJS.ProcessEnv;
23
17
  }): RuntimeBinding;
24
- export declare function resolveStaticRuntimeMode(options: {
25
- appConfig: EcoPagesAppConfig;
26
- cliArgs: ReturnParseCliArgs;
27
- }): StaticRuntimeMode;
@@ -16,8 +16,6 @@ export function resolveRuntimeBinding(options) {
16
16
  const preferredPort = options.cliArgs.port ?? (env.ECOPAGES_PORT ? Number(env.ECOPAGES_PORT) : undefined) ?? DEFAULT_ECOPAGES_PORT;
17
17
  const preferredHostname = options.cliArgs.hostname ?? env.ECOPAGES_HOSTNAME ?? DEFAULT_ECOPAGES_HOSTNAME;
18
18
  return {
19
- preferredPort,
20
- preferredHostname,
21
19
  allowPortFallback: !portExplicitlyConfigured,
22
20
  runtimeOrigin: resolveServeRuntimeOrigin({
23
21
  hostname: preferredHostname,
@@ -31,8 +29,3 @@ export function resolveRuntimeBinding(options) {
31
29
  watch: options.cliArgs.dev,
32
30
  };
33
31
  }
34
- export function resolveStaticRuntimeMode(options) {
35
- return {
36
- canBuildWithoutRuntimeServer: options.cliArgs.build || options.cliArgs.preview,
37
- };
38
- }
@@ -5,8 +5,11 @@ export interface RuntimeHost<TServer, TServeOptions> {
5
5
  }): Promise<void>;
6
6
  getOrigin(server: TServer, fallbackServeOptions: TServeOptions): string;
7
7
  }
8
+ /**
9
+ * @remarks
10
+ * Request handling travels inside `serveOptions`, as Bun's `fetch` does, so each
11
+ * runtime host receives only the callbacks it actually calls.
12
+ */
8
13
  export interface RuntimeHostStartOptions<TServeOptions> {
9
14
  serveOptions: TServeOptions;
10
- handleRequest(request: Request): Promise<Response>;
11
- onError(error: Error): Promise<void> | void;
12
15
  }
@@ -28,7 +28,7 @@ export declare function startDevWarmup(options: {
28
28
  * Releases shared dev resources in a consistent order across server adapters.
29
29
  *
30
30
  * @remarks
31
- * Bun calls `buildRuntime()` during `initialize()` when watch is enabled; Node defers
31
+ * Bun calls `ensureRuntimeReady()` during `initialize()` when watch is enabled; Node defers
32
32
  * runtime creation to `completeInitialization()`. Transport-specific setup stays in
33
33
  * each adapter — only shared teardown lives here.
34
34
  */
@@ -56,7 +56,7 @@ export function startDevWarmup(options) {
56
56
  * Releases shared dev resources in a consistent order across server adapters.
57
57
  *
58
58
  * @remarks
59
- * Bun calls `buildRuntime()` during `initialize()` when watch is enabled; Node defers
59
+ * Bun calls `ensureRuntimeReady()` during `initialize()` when watch is enabled; Node defers
60
60
  * runtime creation to `completeInitialization()`. Transport-specific setup stays in
61
61
  * each adapter — only shared teardown lives here.
62
62
  */
@@ -8,7 +8,7 @@ import { ServerStaticBuilder } from './server-static-builder.js';
8
8
  import { FileSystemResponseMatcher } from '../http/fs-server-response-matcher.js';
9
9
  import { ServerRouteHandler } from './server-route-handler.js';
10
10
  import { ApiRequestPipeline } from '../http/api-request-pipeline.js';
11
- import type { ApiHandler, CacheInvalidator, ErrorHandler, IHmrManager, RenderContext, StaticRoute } from '../../../types/public-types.js';
11
+ import type { ApiHandler, CacheInvalidator, ErrorHandler, IHmrManager, RenderContext, StaticRoute, ErrorPageLoaders } from '../../../types/public-types.js';
12
12
  type SharedHmrAssetManager = IHmrManager;
13
13
  type SharedRequestContext<TServer = unknown> = {
14
14
  apiHandlers: ApiHandler[];
@@ -28,17 +28,24 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
28
28
  protected hostOwnsDevClient: boolean;
29
29
  private devStaticRoutePrewarmStarted;
30
30
  private sharedPageCacheService;
31
+ /** Propagates the actual listening port to every binding-dependent service. */
32
+ applyBoundPort(input: {
33
+ port: number;
34
+ runtimeOrigin: string;
35
+ }): void;
31
36
  /**
32
37
  * Warms declared static paths after the final watch-mode response pipeline exists.
33
38
  */
34
39
  protected startDevStaticRoutePrewarmWhenReady(): Promise<void>;
35
40
  protected initializeSharedRouteHandling(options: {
36
41
  staticRoutes: StaticRoute[];
42
+ errorPageLoaders?: ErrorPageLoaders;
37
43
  hmrManager?: SharedHmrAssetManager;
38
44
  }): Promise<void>;
39
45
  private ensureRouteRendererFactory;
40
46
  protected createSharedWatchRefreshCallback(options: {
41
47
  staticRoutes: StaticRoute[];
48
+ errorPageLoaders?: ErrorPageLoaders;
42
49
  hmrManager?: SharedHmrAssetManager;
43
50
  onRoutesReady?: () => Promise<void> | void;
44
51
  onError?: (error: Error) => Promise<void> | void;
@@ -60,11 +67,12 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
60
67
  * 1. How to render React/Lit pages via `RouteRendererFactory`
61
68
  * 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
62
69
  * 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
63
- *
64
- * @param staticRoutes - A map of explicitly served static assets.
65
- * @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
66
70
  */
67
- protected configureSharedResponseHandlers(staticRoutes: StaticRoute[], hmrManager?: IHmrManager): void;
71
+ protected configureSharedResponseHandlers(options: {
72
+ staticRoutes: StaticRoute[];
73
+ hmrManager?: IHmrManager;
74
+ errorPageLoaders?: ErrorPageLoaders;
75
+ }): void;
68
76
  private createSharedResponseHandlerDependencies;
69
77
  private createSharedPageCacheServiceFromConfig;
70
78
  private getOrCreateSharedPageCacheService;
@@ -74,6 +82,19 @@ export declare abstract class SharedServerAdapter<TOptions extends ServerAdapter
74
82
  private tryHandleSharedHmrRequest;
75
83
  private injectSharedHmrHtmlResponse;
76
84
  private tryHandleSharedApiRequest;
85
+ /**
86
+ * Recognises a runtime-specific client disconnect so it answers 499.
87
+ *
88
+ * @remarks
89
+ * Only the Node adapter overrides it: its request bridge raises a dedicated
90
+ * error when the socket closes while the body is read.
91
+ */
92
+ protected isClientAbortError(_error: unknown): boolean;
93
+ /**
94
+ * Resolves an error that escaped {@link handleSharedRequest} with the same
95
+ * precedence as API handler errors, so `app.onError` sees it on every runtime.
96
+ */
97
+ protected handleUnexpectedRequestError(error: unknown, request: Request, context: SharedRequestContext): Promise<Response>;
77
98
  /**
78
99
  * Universally processes an incoming WinterCG Web standard Request.
79
100
  *
@@ -33,10 +33,17 @@ export class SharedServerAdapter extends AbstractServerAdapter {
33
33
  schemaValidator: this.schemaValidator,
34
34
  getRenderContext: () => this.getRenderContext(),
35
35
  getCacheService: () => this.getCacheService(),
36
+ isClientAbort: (error) => this.isClientAbortError(error),
36
37
  });
37
38
  hostOwnsDevClient = false;
38
39
  devStaticRoutePrewarmStarted = false;
39
40
  sharedPageCacheService;
41
+ /** Propagates the actual listening port to every binding-dependent service. */
42
+ applyBoundPort(input) {
43
+ super.applyBoundPort(input);
44
+ this.routeRendererFactory?.setRuntimeOrigin(input.runtimeOrigin);
45
+ this.staticBuilder?.setRuntimeBinding(input);
46
+ }
40
47
  /**
41
48
  * Warms declared static paths after the final watch-mode response pipeline exists.
42
49
  */
@@ -72,7 +79,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
72
79
  async initializeSharedRouteHandling(options) {
73
80
  this.ensureRouteRendererFactory();
74
81
  await this.initSharedRouter();
75
- this.configureSharedResponseHandlers(options.staticRoutes, options.hmrManager);
82
+ this.configureSharedResponseHandlers(options);
76
83
  }
77
84
  ensureRouteRendererFactory() {
78
85
  if (this.routeRendererFactory) {
@@ -89,6 +96,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
89
96
  try {
90
97
  await this.initializeSharedRouteHandling({
91
98
  staticRoutes: options.staticRoutes,
99
+ errorPageLoaders: options.errorPageLoaders,
92
100
  hmrManager: options.hmrManager,
93
101
  });
94
102
  if (options.onRoutesReady) {
@@ -147,22 +155,19 @@ export class SharedServerAdapter extends AbstractServerAdapter {
147
155
  * 1. How to render React/Lit pages via `RouteRendererFactory`
148
156
  * 2. How to match logical routes to physical filesystem artifacts via `FileSystemResponseMatcher`
149
157
  * 3. Whether to serve the response from the embedded `PageCacheService` or generate it fresh on the fly.
150
- *
151
- * @param staticRoutes - A map of explicitly served static assets.
152
- * @param hmrManager - The runtime-specific Hot Module Replacement orchestrator (if watching).
153
158
  */
154
- configureSharedResponseHandlers(staticRoutes, hmrManager) {
159
+ configureSharedResponseHandlers(options) {
155
160
  this.ensureRouteRendererFactory();
156
- const { fileSystemResponseMatcher, explicitStaticRouteMatcher } = this.createSharedResponseHandlerDependencies(staticRoutes);
161
+ const { fileSystemResponseMatcher, explicitStaticRouteMatcher } = this.createSharedResponseHandlerDependencies(options.staticRoutes, options.errorPageLoaders);
157
162
  this.fileSystemResponseMatcher = fileSystemResponseMatcher;
158
163
  this.routeHandler = new ServerRouteHandler({
159
164
  router: this.router,
160
165
  fileSystemResponseMatcher: this.fileSystemResponseMatcher,
161
166
  explicitStaticRouteMatcher,
162
- hmrManager,
167
+ hmrManager: options.hmrManager,
163
168
  });
164
169
  }
165
- createSharedResponseHandlerDependencies(staticRoutes) {
170
+ createSharedResponseHandlerDependencies(staticRoutes, errorPageLoaders) {
166
171
  const fileSystemResponseFactory = new FileSystemServerResponseFactory({
167
172
  options: {
168
173
  watchMode: !!this.options?.watch,
@@ -174,6 +179,7 @@ export class SharedServerAdapter extends AbstractServerAdapter {
174
179
  assetPrefix: path.join(this.appConfig.rootDir, this.appConfig.distDir),
175
180
  router: this.router,
176
181
  routeRendererFactory: this.routeRendererFactory,
182
+ errorPageLoaders,
177
183
  fileSystemResponseFactory,
178
184
  cacheService,
179
185
  defaultCacheStrategy: this.appConfig.cache?.defaultStrategy ?? 'static',
@@ -256,6 +262,27 @@ export class SharedServerAdapter extends AbstractServerAdapter {
256
262
  async tryHandleSharedApiRequest(request, context) {
257
263
  return await this.apiRequestPipeline.tryHandle(request, context.apiHandlers, context.serverInstance, context.errorHandler);
258
264
  }
265
+ /**
266
+ * Recognises a runtime-specific client disconnect so it answers 499.
267
+ *
268
+ * @remarks
269
+ * Only the Node adapter overrides it: its request bridge raises a dedicated
270
+ * error when the socket closes while the body is read.
271
+ */
272
+ isClientAbortError(_error) {
273
+ return false;
274
+ }
275
+ /**
276
+ * Resolves an error that escaped {@link handleSharedRequest} with the same
277
+ * precedence as API handler errors, so `app.onError` sees it on every runtime.
278
+ */
279
+ async handleUnexpectedRequestError(error, request, context) {
280
+ return await this.apiRequestPipeline.handleError(error, {
281
+ request,
282
+ serverInstance: context.serverInstance,
283
+ errorHandler: context.errorHandler,
284
+ });
285
+ }
259
286
  /**
260
287
  * Universally processes an incoming WinterCG Web standard Request.
261
288
  *
@@ -40,7 +40,15 @@ export class ServerRouteHandler {
40
40
  const pathname = new URL(request.url).pathname;
41
41
  const explicitMatch = this.explicitStaticRouteMatcher?.match(request.url);
42
42
  if (explicitMatch) {
43
- return await this.explicitStaticRouteMatcher.handleMatch(explicitMatch);
43
+ try {
44
+ return await this.explicitStaticRouteMatcher.handleMatch(explicitMatch);
45
+ }
46
+ catch (error) {
47
+ if (error instanceof Response) {
48
+ return error;
49
+ }
50
+ return await this.fileSystemResponseMatcher.renderServerError(pathname, error);
51
+ }
44
52
  }
45
53
  const fsMatch = !pathname.includes('.') && this.router.matchRequest(request.url);
46
54
  return await (fsMatch
@@ -59,8 +67,8 @@ export class ServerRouteHandler {
59
67
  * @throws HttpError for standard HTTP errors
60
68
  */
61
69
  async handleNoMatch(request) {
70
+ const pathname = new URL(request.url).pathname;
62
71
  try {
63
- const pathname = new URL(request.url).pathname;
64
72
  return await this.fileSystemResponseMatcher.handleNoMatch(pathname);
65
73
  }
66
74
  catch (error) {
@@ -71,7 +79,7 @@ export class ServerRouteHandler {
71
79
  this.hmrManager?.broadcast({ type: 'error', message: error.message });
72
80
  appLogger.error('Error handling no match:', error);
73
81
  }
74
- return new Response('Internal Server Error', { status: 500 });
82
+ return await this.fileSystemResponseMatcher.renderServerError(pathname, error);
75
83
  }
76
84
  }
77
85
  }
@@ -1,6 +1,6 @@
1
1
  import type { EcoPagesAppConfig, IHmrManager } from '../../../types/internal-types.js';
2
2
  import type { EcoBuildPlugin } from '../../../build/contracts/build-types.js';
3
- import type { StaticRoute } from '../../../types/public-types.js';
3
+ import type { ErrorPageLoaders, StaticRoute } from '../../../types/public-types.js';
4
4
  import type { RouteRegistry } from '../../../router/server/route-registry.js';
5
5
  import type { StaticSiteGenerator } from '../../../static-site-generator/static-site-generator.js';
6
6
  import type { StaticGenerationRendererResolver } from '../../../route-renderer/route-renderer.js';
@@ -43,14 +43,19 @@ export interface ServerStaticBuilderLogger {
43
43
  export declare class ServerStaticBuilder {
44
44
  private readonly appConfig;
45
45
  private readonly staticSiteGenerator;
46
- private readonly serveOptions;
47
- private readonly runtimeOrigin;
46
+ private serveOptions;
47
+ private runtimeOrigin;
48
48
  private readonly needsServerBundle;
49
49
  private readonly logger;
50
50
  private readonly entryFile;
51
51
  private readonly hmrManager?;
52
52
  private readonly onRuntimePlugin?;
53
53
  constructor({ appConfig, staticSiteGenerator, serveOptions, runtimeOrigin, needsServerBundle, logger, entryFile, hmrManager, onRuntimePlugin, }: ServerStaticBuilderParams);
54
+ /** Keeps build-time URLs aligned with the server's actual listening port. */
55
+ setRuntimeBinding(input: {
56
+ port: number;
57
+ runtimeOrigin: string;
58
+ }): void;
54
59
  private prepareExportDirectory;
55
60
  private refreshRuntimeAssets;
56
61
  /**
@@ -82,5 +87,6 @@ export declare class ServerStaticBuilder {
82
87
  router: RouteRegistry;
83
88
  routeRendererFactory: StaticGenerationRendererResolver;
84
89
  staticRoutes?: StaticRoute[];
90
+ errorPageLoaders?: ErrorPageLoaders;
85
91
  }): Promise<void>;
86
92
  }
@@ -2,12 +2,14 @@ import path from 'node:path';
2
2
  import { fileSystem } from '@ecopages/file-system';
3
3
  import { DEFAULT_ECOPAGES_HOSTNAME, DEFAULT_ECOPAGES_PORT } from '../../../config/constants.js';
4
4
  import { appLogger } from '../../../global/app-logger.js';
5
- import { build, getAppBuildAdapter, setupAppRuntimePlugins } from '../../../build/build-adapter.js';
5
+ import { build, setupAppRuntimePlugins } from '../../../build/build-adapter.js';
6
+ import { createServerBundleStagingDirectory, publishServerBundleDirectory, removeServerBundleStagingDirectory, resolvePublishedServerBundlePaths, } from '../../../build/server-bundle-publication.js';
6
7
  import { createServerBuildRequest } from '../../../build/runtime/build-request-policy.js';
7
8
  import { requireBuildRuntime } from '../../../build/runtime/build-runtime.js';
8
9
  import { attachHmrToIntegrations } from './runtime-server-lifecycle.js';
9
- import { getServerBundleOutputPaths, lookupServerEntryBuildCache, recordServerEntryBuildCache, writeServerBundleDeployManifest, } from '../../../build/cache/server-entry-build-cache.js';
10
+ import { getServerBundleOutputPaths, lookupServerEntryBuildCache, recordServerEntryBuildCache, SERVER_BUNDLE_MANIFEST_FILENAME, writeServerBundleDeployManifest, } from '../../../build/cache/server-entry-build-cache.js';
10
11
  import { clearProductionBuildCaches, shouldResetStaticExportDirectory, } from '../../../static-site-generator/static-build-invalidation.js';
12
+ import { assertCanBundleServerConfig, bundleEcoConfigModule, EMITTED_ECO_CONFIG_FILENAME, } from '../../../config/server-config-bundle.js';
11
13
  import { resolveEntryFile, SERVER_BUNDLE_FILENAME } from '../../../utils/resolve-entry-file.js';
12
14
  /**
13
15
  * Handles static site generation.
@@ -33,6 +35,11 @@ export class ServerStaticBuilder {
33
35
  this.hmrManager = hmrManager;
34
36
  this.onRuntimePlugin = onRuntimePlugin;
35
37
  }
38
+ /** Keeps build-time URLs aligned with the server's actual listening port. */
39
+ setRuntimeBinding(input) {
40
+ this.serveOptions = { ...this.serveOptions, port: input.port };
41
+ this.runtimeOrigin = input.runtimeOrigin;
42
+ }
36
43
  prepareExportDirectory(force) {
37
44
  if (force) {
38
45
  clearProductionBuildCaches(this.appConfig);
@@ -87,56 +94,70 @@ export class ServerStaticBuilder {
87
94
  * @throws If the build adapter is unavailable, is host-owned, or bundling fails.
88
95
  */
89
96
  async bundleServerEntry(options) {
90
- const buildAdapter = getAppBuildAdapter(this.appConfig);
91
- if (buildAdapter.ownership === 'vite-host') {
92
- throw new Error('Cannot bundle the server entry file: build ownership is "vite-host". ' +
93
- 'The host runtime is expected to produce its own server bundle.');
94
- }
97
+ assertCanBundleServerConfig(this.appConfig);
95
98
  const entryPath = path.isAbsolute(this.entryFile)
96
99
  ? this.entryFile
97
100
  : path.join(this.appConfig.rootDir, this.entryFile);
98
101
  if (!fileSystem.exists(entryPath)) {
99
102
  throw new Error(`Cannot bundle server entry: file "${this.entryFile}" not found in "${this.appConfig.rootDir}".`);
100
103
  }
101
- const { serverOutdir, serverEntryPath } = getServerBundleOutputPaths(this.appConfig);
104
+ const { serverOutdir } = getServerBundleOutputPaths(this.appConfig);
102
105
  const cached = lookupServerEntryBuildCache({
103
106
  appConfig: this.appConfig,
104
107
  entryPath,
105
108
  force: options?.force,
106
109
  });
107
110
  if (cached) {
108
- const hasBundle = cached.outputPaths.some((outputPath) => path.resolve(outputPath) === path.resolve(serverEntryPath) && fileSystem.exists(outputPath));
109
- if (hasBundle) {
110
- this.logger.info('Reusing cached server entry bundle');
111
- writeServerBundleDeployManifest(this.appConfig, serverEntryPath);
112
- return;
113
- }
111
+ this.logger.info('Reusing cached server entry bundle');
112
+ return;
114
113
  }
115
114
  this.logger.info('Bundling server entry file...');
116
- const buildOptions = createServerBuildRequest(this.appConfig, {
117
- profile: 'server-entry',
118
- entrypoints: [entryPath],
119
- outdir: serverOutdir,
120
- naming: SERVER_BUNDLE_FILENAME,
121
- sourcemap: 'hidden',
122
- });
123
- const result = await build(buildOptions, requireBuildRuntime(this.appConfig).getProfile('server-entry'));
124
- if (!result.success) {
125
- const errorMessages = result.logs.map((log) => log.message).join('\n');
126
- throw new Error(`Failed to bundle server entry file:\n${errorMessages}`);
115
+ const stagingDir = createServerBundleStagingDirectory(serverOutdir);
116
+ try {
117
+ const configBundle = await bundleEcoConfigModule(this.appConfig, {
118
+ outputDir: stagingDir,
119
+ runtimeDir: serverOutdir,
120
+ });
121
+ const stagedServerEntryPath = path.join(stagingDir, SERVER_BUNDLE_FILENAME);
122
+ const buildOptions = createServerBuildRequest(this.appConfig, {
123
+ profile: 'server-entry',
124
+ entrypoints: [entryPath],
125
+ outdir: stagingDir,
126
+ naming: SERVER_BUNDLE_FILENAME,
127
+ sourcemap: 'hidden',
128
+ });
129
+ const result = await build(buildOptions, requireBuildRuntime(this.appConfig).getProfile('server-entry'));
130
+ if (!result.success) {
131
+ const errorMessages = result.logs.map((log) => log.message).join('\n');
132
+ throw new Error(`Failed to bundle server entry file:\n${errorMessages}`);
133
+ }
134
+ writeServerBundleDeployManifest(this.appConfig, stagedServerEntryPath, {
135
+ sourceConfigPath: this.appConfig.absolutePaths.config,
136
+ emittedConfigModule: configBundle ? EMITTED_ECO_CONFIG_FILENAME : undefined,
137
+ outputDir: stagingDir,
138
+ });
139
+ const stagedOutputPaths = [
140
+ ...(result.outputs.length > 0
141
+ ? result.outputs.map((output) => output.path)
142
+ : fileSystem.exists(stagedServerEntryPath)
143
+ ? [stagedServerEntryPath]
144
+ : []),
145
+ ...(configBundle ? [configBundle.emittedConfigPath] : []),
146
+ path.join(stagingDir, SERVER_BUNDLE_MANIFEST_FILENAME),
147
+ ];
148
+ const outputPaths = resolvePublishedServerBundlePaths(stagedOutputPaths, stagingDir, serverOutdir);
149
+ publishServerBundleDirectory(stagingDir, serverOutdir);
150
+ recordServerEntryBuildCache({
151
+ appConfig: this.appConfig,
152
+ entryPath,
153
+ buildResult: result,
154
+ configBuildResult: configBundle?.buildResult,
155
+ outputPaths,
156
+ });
157
+ }
158
+ finally {
159
+ removeServerBundleStagingDirectory(stagingDir);
127
160
  }
128
- const outputPaths = result.outputs.length > 0
129
- ? result.outputs.map((output) => output.path)
130
- : fileSystem.exists(serverEntryPath)
131
- ? [serverEntryPath]
132
- : [];
133
- recordServerEntryBuildCache({
134
- appConfig: this.appConfig,
135
- entryPath,
136
- buildResult: result,
137
- outputPaths,
138
- });
139
- writeServerBundleDeployManifest(this.appConfig, serverEntryPath);
140
161
  this.logger.info('Server entry file bundled successfully');
141
162
  }
142
163
  /**
@@ -159,6 +180,7 @@ export class ServerStaticBuilder {
159
180
  baseUrl,
160
181
  routeRendererFactory: dependencies.routeRendererFactory,
161
182
  staticRoutes: dependencies.staticRoutes,
183
+ errorPageLoaders: dependencies.errorPageLoaders,
162
184
  force,
163
185
  preserveExportDirectory,
164
186
  });
@@ -12,10 +12,18 @@ export type AttachNodeHttpWebSocketUpgradesOptions = {
12
12
  passthroughUnmatched?: boolean;
13
13
  preflight?: NodeHttpWebSocketUpgradePreflight;
14
14
  };
15
+ /** Upgrade options a host passes when it attaches Ecopages to a server it shares. */
16
+ export type WebSocketUpgradeOptions = Pick<AttachNodeHttpWebSocketUpgradesOptions, 'passthroughUnmatched'>;
15
17
  /**
16
- * Wires Ecopages user WebSocket routes onto a Node HTTP server's `upgrade` event.
18
+ * Wires Ecopages WebSocket upgrades onto a Node HTTP server's `upgrade` event.
17
19
  *
18
20
  * Used by the Node adapter in standalone mode and by host integrations such as
19
21
  * the Vite plugin that embed Ecopages behind a foreign HTTP server.
22
+ *
23
+ * @remarks
24
+ * This is the single owner of the unmatched-upgrade policy: an upgrade claimed
25
+ * by `preflight` (for example `/_hmr`) or a user route is handled here, and
26
+ * anything else is destroyed unless `passthroughUnmatched` leaves it for other
27
+ * listeners on a shared server.
20
28
  */
21
29
  export declare function attachNodeHttpWebSocketUpgrades(server: NodeHttpServer, options: AttachNodeHttpWebSocketUpgradesOptions): void;
@@ -71,13 +71,19 @@ async function setupNodeWebSocketConnection(ws, wsMatch, req, runtimeOrigin, sea
71
71
  });
72
72
  }
73
73
  /**
74
- * Wires Ecopages user WebSocket routes onto a Node HTTP server's `upgrade` event.
74
+ * Wires Ecopages WebSocket upgrades onto a Node HTTP server's `upgrade` event.
75
75
  *
76
76
  * Used by the Node adapter in standalone mode and by host integrations such as
77
77
  * the Vite plugin that embed Ecopages behind a foreign HTTP server.
78
+ *
79
+ * @remarks
80
+ * This is the single owner of the unmatched-upgrade policy: an upgrade claimed
81
+ * by `preflight` (for example `/_hmr`) or a user route is handled here, and
82
+ * anything else is destroyed unless `passthroughUnmatched` leaves it for other
83
+ * listeners on a shared server.
78
84
  */
79
85
  export function attachNodeHttpWebSocketUpgrades(server, options) {
80
- if (options.websocketHandlers.size === 0) {
86
+ if (options.websocketHandlers.size === 0 && !options.preflight) {
81
87
  return;
82
88
  }
83
89
  if (attachedUpgradeServers.has(server)) {