@ecopages/core 0.2.0-alpha.7 → 0.2.0-alpha.9
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/CHANGELOG.md +31 -0
- package/package.json +212 -92
- package/src/adapters/abstract/application-adapter.d.ts +168 -0
- package/src/adapters/abstract/application-adapter.js +109 -0
- package/src/adapters/abstract/router-adapter.d.ts +26 -0
- package/src/adapters/abstract/router-adapter.js +5 -0
- package/src/adapters/abstract/server-adapter.d.ts +69 -0
- package/src/adapters/abstract/server-adapter.js +15 -0
- package/src/adapters/bun/client-bridge.d.ts +34 -0
- package/src/adapters/bun/client-bridge.js +48 -0
- package/src/adapters/bun/create-app.d.ts +60 -0
- package/src/adapters/bun/create-app.js +117 -0
- package/src/adapters/bun/hmr-manager.d.ts +143 -0
- package/src/adapters/bun/hmr-manager.js +334 -0
- package/src/adapters/bun/index.d.ts +2 -0
- package/src/adapters/bun/index.js +8 -0
- package/src/adapters/bun/server-adapter.d.ts +155 -0
- package/src/adapters/bun/server-adapter.js +373 -0
- package/src/adapters/bun/server-lifecycle.d.ts +63 -0
- package/src/adapters/bun/server-lifecycle.js +92 -0
- package/src/adapters/index.d.ts +6 -0
- package/src/adapters/index.js +14 -0
- package/src/adapters/node/bootstrap-dependency-resolver.d.ts +44 -0
- package/src/adapters/node/bootstrap-dependency-resolver.js +172 -0
- package/src/adapters/node/create-app.d.ts +21 -0
- package/src/adapters/node/create-app.js +143 -0
- package/src/adapters/node/index.d.ts +6 -0
- package/src/adapters/node/index.js +11 -0
- package/src/adapters/node/node-client-bridge.d.ts +26 -0
- package/src/adapters/node/node-client-bridge.js +66 -0
- package/src/adapters/node/node-hmr-manager.d.ts +133 -0
- package/src/adapters/node/node-hmr-manager.js +312 -0
- package/src/adapters/node/runtime-adapter.d.ts +46 -0
- package/src/adapters/node/runtime-adapter.js +306 -0
- package/src/adapters/node/server-adapter.d.ts +161 -0
- package/src/adapters/node/server-adapter.js +358 -0
- package/src/adapters/node/static-content-server.d.ts +60 -0
- package/src/adapters/node/static-content-server.js +194 -0
- package/src/adapters/node/write-runtime-manifest.d.ts +26 -0
- package/src/adapters/node/write-runtime-manifest.js +12 -0
- package/src/adapters/shared/api-response.d.ts +52 -0
- package/src/adapters/shared/api-response.js +96 -0
- package/src/adapters/shared/application-adapter.d.ts +18 -0
- package/src/adapters/shared/application-adapter.js +90 -0
- package/src/adapters/shared/define-api-handler.d.ts +25 -0
- package/src/adapters/shared/define-api-handler.js +15 -0
- package/src/adapters/shared/explicit-static-route-matcher.d.ts +38 -0
- package/src/adapters/shared/explicit-static-route-matcher.js +103 -0
- package/src/adapters/shared/file-route-middleware-pipeline.d.ts +65 -0
- package/src/adapters/shared/file-route-middleware-pipeline.js +99 -0
- package/src/adapters/shared/fs-server-response-factory.d.ts +19 -0
- package/src/adapters/shared/fs-server-response-factory.js +97 -0
- package/src/adapters/shared/fs-server-response-matcher.d.ts +75 -0
- package/src/adapters/shared/fs-server-response-matcher.js +160 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.d.ts +55 -0
- package/src/adapters/shared/hmr-entrypoint-registrar.js +87 -0
- package/src/adapters/shared/hmr-html-response.d.ts +22 -0
- package/src/adapters/shared/hmr-html-response.js +32 -0
- package/src/adapters/shared/render-context.d.ts +14 -0
- package/src/adapters/shared/render-context.js +70 -0
- package/src/adapters/shared/runtime-bootstrap.d.ts +38 -0
- package/src/adapters/shared/runtime-bootstrap.js +43 -0
- package/src/adapters/shared/server-adapter.d.ts +97 -0
- package/src/adapters/shared/server-adapter.js +386 -0
- package/src/adapters/shared/server-route-handler.d.ts +89 -0
- package/src/adapters/shared/server-route-handler.js +111 -0
- package/src/adapters/shared/server-static-builder.d.ts +70 -0
- package/src/adapters/shared/server-static-builder.js +99 -0
- package/src/build/build-adapter.d.ts +186 -0
- package/src/build/build-adapter.js +168 -0
- package/src/build/build-manifest.d.ts +27 -0
- package/src/build/build-manifest.js +30 -0
- package/src/build/build-types.d.ts +57 -0
- package/src/build/build-types.js +0 -0
- package/src/build/dev-build-coordinator.d.ts +74 -0
- package/src/build/dev-build-coordinator.js +161 -0
- package/src/build/esbuild-build-adapter.d.ts +72 -0
- package/src/build/esbuild-build-adapter.js +422 -0
- package/src/build/runtime-build-executor.d.ts +13 -0
- package/src/build/runtime-build-executor.js +20 -0
- package/src/build/runtime-specifier-alias-plugin.d.ts +15 -0
- package/src/build/runtime-specifier-alias-plugin.js +31 -0
- package/src/config/config-builder.d.ts +238 -0
- package/src/config/config-builder.js +565 -0
- package/src/constants.d.ts +45 -0
- package/src/constants.js +25 -0
- package/src/create-app.d.ts +17 -0
- package/src/create-app.js +66 -0
- package/src/dev/sc-server.d.ts +30 -0
- package/src/dev/sc-server.js +111 -0
- package/src/eco/component-render-context.d.ts +105 -0
- package/src/eco/component-render-context.js +87 -0
- package/src/eco/eco.d.ts +9 -0
- package/src/eco/eco.js +114 -0
- package/src/eco/eco.types.d.ts +178 -0
- package/src/eco/eco.types.js +0 -0
- package/src/eco/eco.utils.d.ts +40 -0
- package/src/eco/eco.utils.js +40 -0
- package/src/eco/global-injector-map.d.ts +16 -0
- package/src/eco/global-injector-map.js +80 -0
- package/src/eco/lazy-injector-map.d.ts +8 -0
- package/src/eco/lazy-injector-map.js +70 -0
- package/src/eco/module-dependencies.d.ts +18 -0
- package/src/eco/module-dependencies.js +49 -0
- package/src/errors/http-error.d.ts +31 -0
- package/src/errors/http-error.js +50 -0
- package/src/errors/index.d.ts +2 -0
- package/src/errors/index.js +4 -0
- package/src/errors/locals-access-error.d.ts +4 -0
- package/src/errors/locals-access-error.js +9 -0
- package/src/global/app-logger.d.ts +2 -0
- package/src/global/app-logger.js +6 -0
- package/src/hmr/client/hmr-runtime.d.ts +5 -0
- package/src/hmr/client/hmr-runtime.js +109 -0
- package/src/hmr/hmr-strategy.d.ts +159 -0
- package/src/hmr/hmr-strategy.js +29 -0
- package/src/hmr/hmr.postcss.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.postcss.test.e2e.js +31 -0
- package/src/hmr/hmr.test.e2e.d.ts +1 -0
- package/src/hmr/hmr.test.e2e.js +43 -0
- package/src/hmr/strategies/default-hmr-strategy.d.ts +43 -0
- package/src/hmr/strategies/default-hmr-strategy.js +34 -0
- package/src/hmr/strategies/js-hmr-strategy.d.ts +139 -0
- package/src/hmr/strategies/js-hmr-strategy.js +178 -0
- package/src/index.browser.d.ts +3 -0
- package/src/index.browser.js +4 -0
- package/src/index.d.ts +5 -0
- package/src/index.js +10 -0
- package/src/integrations/ghtml/ghtml-renderer.d.ts +15 -0
- package/src/integrations/ghtml/ghtml-renderer.js +62 -0
- package/src/integrations/ghtml/ghtml.plugin.d.ts +20 -0
- package/src/integrations/ghtml/ghtml.plugin.js +21 -0
- package/src/internal-types.d.ts +221 -0
- package/src/internal-types.js +0 -0
- package/src/plugins/alias-resolver-plugin.d.ts +2 -0
- package/src/plugins/alias-resolver-plugin.js +53 -0
- package/src/plugins/eco-component-meta-plugin.d.ts +97 -0
- package/src/plugins/eco-component-meta-plugin.js +157 -0
- package/src/plugins/integration-plugin.d.ts +136 -0
- package/src/plugins/integration-plugin.js +133 -0
- package/src/plugins/processor.d.ts +95 -0
- package/src/plugins/processor.js +136 -0
- package/src/plugins/runtime-capability.d.ts +9 -0
- package/src/plugins/runtime-capability.js +0 -0
- package/src/public-types.d.ts +1149 -0
- package/src/public-types.js +0 -0
- package/src/route-renderer/component-graph/component-graph-executor.d.ts +32 -0
- package/src/route-renderer/component-graph/component-graph-executor.js +31 -0
- package/src/route-renderer/component-graph/component-graph.d.ts +42 -0
- package/src/route-renderer/component-graph/component-graph.js +72 -0
- package/src/route-renderer/component-graph/component-marker.d.ts +52 -0
- package/src/route-renderer/component-graph/component-marker.js +46 -0
- package/src/route-renderer/component-graph/component-reference.d.ts +10 -0
- package/src/route-renderer/component-graph/component-reference.js +19 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.d.ts +77 -0
- package/src/route-renderer/component-graph/marker-graph-resolver.js +95 -0
- package/src/route-renderer/orchestration/integration-renderer.d.ts +372 -0
- package/src/route-renderer/orchestration/integration-renderer.js +589 -0
- package/src/route-renderer/orchestration/render-execution.service.d.ts +103 -0
- package/src/route-renderer/orchestration/render-execution.service.js +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.d.ts +121 -0
- package/src/route-renderer/orchestration/render-preparation.service.js +332 -0
- package/src/route-renderer/page-loading/dependency-resolver.d.ts +35 -0
- package/src/route-renderer/page-loading/dependency-resolver.js +442 -0
- package/src/route-renderer/page-loading/page-module-loader.d.ts +87 -0
- package/src/route-renderer/page-loading/page-module-loader.js +124 -0
- package/src/route-renderer/route-renderer.d.ts +61 -0
- package/src/route-renderer/route-renderer.js +87 -0
- package/src/router/client/link-intent.js +34 -0
- package/src/router/client/link-intent.test.browser.d.ts +1 -0
- package/src/router/client/link-intent.test.browser.js +43 -0
- package/src/router/client/navigation-coordinator.d.ts +149 -0
- package/src/router/client/navigation-coordinator.js +215 -0
- package/src/router/server/fs-router-scanner.d.ts +41 -0
- package/src/router/server/fs-router-scanner.js +156 -0
- package/src/router/server/fs-router.d.ts +26 -0
- package/src/router/server/fs-router.js +100 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.d.ts +120 -0
- package/src/services/assets/asset-processing-service/asset-processing.service.js +331 -0
- package/src/services/assets/asset-processing-service/asset.factory.d.ts +17 -0
- package/src/services/assets/asset-processing-service/asset.factory.js +82 -0
- package/src/services/assets/asset-processing-service/assets.types.d.ts +89 -0
- package/src/services/assets/asset-processing-service/assets.types.js +0 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.d.ts +55 -0
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.js +48 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.d.ts +20 -0
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.js +41 -0
- package/src/services/assets/asset-processing-service/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/index.js +5 -0
- package/src/services/assets/asset-processing-service/processor.interface.d.ts +22 -0
- package/src/services/assets/asset-processing-service/processor.interface.js +6 -0
- package/src/services/assets/asset-processing-service/processor.registry.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processor.registry.js +15 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.d.ts +24 -0
- package/src/services/assets/asset-processing-service/processors/base/base-processor.js +64 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.d.ts +17 -0
- package/src/services/assets/asset-processing-service/processors/base/base-script-processor.js +72 -0
- package/src/services/assets/asset-processing-service/processors/index.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/index.js +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/script/content-script.processor.js +57 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.d.ts +8 -0
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.js +76 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.d.ts +7 -0
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.js +75 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.d.ts +5 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.js +25 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.d.ts +9 -0
- package/src/services/assets/asset-processing-service/processors/stylesheet/file-stylesheet.processor.js +66 -0
- package/src/services/assets/browser-bundle.service.d.ts +32 -0
- package/src/services/assets/browser-bundle.service.js +33 -0
- package/src/services/cache/cache.types.d.ts +107 -0
- package/src/services/cache/cache.types.js +0 -0
- package/src/services/cache/index.d.ts +7 -0
- package/src/services/cache/index.js +7 -0
- package/src/services/cache/memory-cache-store.d.ts +42 -0
- package/src/services/cache/memory-cache-store.js +98 -0
- package/src/services/cache/page-cache-service.d.ts +70 -0
- package/src/services/cache/page-cache-service.js +152 -0
- package/src/services/cache/page-request-cache-coordinator.service.d.ts +75 -0
- package/src/services/cache/page-request-cache-coordinator.service.js +109 -0
- package/src/services/html/html-rewriter-provider.service.d.ts +37 -0
- package/src/services/html/html-rewriter-provider.service.js +65 -0
- package/src/services/html/html-transformer.service.d.ts +77 -0
- package/src/services/html/html-transformer.service.js +221 -0
- package/src/services/invalidation/development-invalidation.service.d.ts +74 -0
- package/src/services/invalidation/development-invalidation.service.js +189 -0
- package/src/services/module-loading/app-server-module-transpiler.service.d.ts +16 -0
- package/src/services/module-loading/app-server-module-transpiler.service.js +34 -0
- package/src/services/module-loading/page-module-import.service.d.ts +71 -0
- package/src/services/module-loading/page-module-import.service.js +132 -0
- package/src/services/module-loading/server-loader.service.d.ts +96 -0
- package/src/services/module-loading/server-loader.service.js +32 -0
- package/src/services/module-loading/server-module-transpiler.service.d.ts +69 -0
- package/src/services/module-loading/server-module-transpiler.service.js +61 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.d.ts +35 -0
- package/src/services/runtime-manifest/node-runtime-manifest.service.js +60 -0
- package/src/services/runtime-state/dev-graph.service.d.ts +118 -0
- package/src/services/runtime-state/dev-graph.service.js +162 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.d.ts +41 -0
- package/src/services/runtime-state/entrypoint-dependency-graph.service.js +85 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.d.ts +69 -0
- package/src/services/runtime-state/runtime-specifier-registry.service.js +37 -0
- package/src/services/runtime-state/server-invalidation-state.service.d.ts +26 -0
- package/src/services/runtime-state/server-invalidation-state.service.js +35 -0
- package/src/services/validation/schema-validation-service.d.ts +122 -0
- package/src/services/validation/schema-validation-service.js +101 -0
- package/src/services/validation/standard-schema.types.d.ts +65 -0
- package/src/services/validation/standard-schema.types.js +0 -0
- package/src/static-site-generator/static-site-generator.d.ts +109 -0
- package/src/static-site-generator/static-site-generator.js +353 -0
- package/src/utils/css.d.ts +1 -0
- package/src/utils/css.js +7 -0
- package/src/utils/deep-merge.d.ts +14 -0
- package/src/utils/deep-merge.js +32 -0
- package/src/utils/hash.d.ts +1 -0
- package/src/utils/hash.js +7 -0
- package/src/utils/html.d.ts +1 -0
- package/src/utils/html.js +4 -0
- package/src/utils/invariant.d.ts +5 -0
- package/src/utils/invariant.js +11 -0
- package/src/utils/locals-utils.d.ts +15 -0
- package/src/utils/locals-utils.js +24 -0
- package/src/utils/parse-cli-args.d.ts +24 -0
- package/src/utils/parse-cli-args.js +47 -0
- package/src/utils/path-utils.module.d.ts +5 -0
- package/src/utils/path-utils.module.js +14 -0
- package/src/utils/resolve-work-dir.d.ts +11 -0
- package/src/utils/resolve-work-dir.js +31 -0
- package/src/utils/runtime.d.ts +11 -0
- package/src/utils/runtime.js +40 -0
- package/src/utils/server-utils.module.d.ts +19 -0
- package/src/utils/server-utils.module.js +56 -0
- package/src/watchers/project-watcher.d.ts +136 -0
- package/src/watchers/project-watcher.js +281 -0
- package/src/watchers/project-watcher.test-helpers.d.ts +4 -0
- package/src/watchers/project-watcher.test-helpers.js +52 -0
- package/src/adapters/bun/hmr-manager.test.ts +0 -267
- package/src/adapters/node/bootstrap-dependency-resolver.test.ts +0 -282
- package/src/adapters/node/node-client-bridge.test.ts +0 -198
- package/src/adapters/node/node-hmr-manager.test.ts +0 -322
- package/src/adapters/node/runtime-adapter.test.ts +0 -868
- package/src/adapters/node/static-content-server.test.ts +0 -60
- package/src/adapters/shared/api-response.test.ts +0 -97
- package/src/adapters/shared/explicit-static-route-matcher.test.ts +0 -381
- package/src/adapters/shared/file-route-middleware-pipeline.test.ts +0 -90
- package/src/adapters/shared/fs-server-response-factory.test.ts +0 -187
- package/src/adapters/shared/fs-server-response-matcher.test.ts +0 -286
- package/src/adapters/shared/hmr-manager.contract.test.ts +0 -196
- package/src/adapters/shared/hmr-manager.dispatch.test.ts +0 -220
- package/src/adapters/shared/render-context.test.ts +0 -146
- package/src/adapters/shared/server-adapter.test.ts +0 -77
- package/src/adapters/shared/server-route-handler.test.ts +0 -110
- package/src/adapters/shared/server-static-builder.test.ts +0 -316
- package/src/build/build-adapter-serialization.test.ts +0 -268
- package/src/build/build-adapter.test.ts +0 -815
- package/src/build/runtime-specifier-alias-plugin.test.ts +0 -43
- package/src/config/config-builder.test.ts +0 -410
- package/src/eco/eco.test.ts +0 -678
- package/src/eco/eco.utils.test.ts +0 -124
- package/src/eco/global-injector-map.test.ts +0 -42
- package/src/eco/lazy-injector-map.test.ts +0 -66
- package/src/eco/module-dependencies.test.ts +0 -30
- package/src/errors/http-error.test.ts +0 -134
- package/src/global/utils.test.ts +0 -12
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-have-HMR-script-injected-in-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-HMR-Server-Integration-should-load-fixture-app-page-1.png +0 -0
- package/src/hmr/client/__screenshots__/hmr-runtime.test.browser.ts/HMR-Runtime-WebSocket-Connection-should-connect-to-correct-HMR-endpoint-1.png +0 -0
- package/src/hmr/hmr-strategy.test.ts +0 -124
- package/src/hmr/strategies/js-hmr-strategy.test.ts +0 -335
- package/src/integrations/ghtml/ghtml-renderer.test.ts +0 -63
- package/src/plugins/alias-resolver-plugin.test.ts +0 -41
- package/src/plugins/eco-component-meta-plugin.test.ts +0 -380
- package/src/plugins/integration-plugin.test.ts +0 -111
- package/src/plugins/processor.test.ts +0 -148
- package/src/route-renderer/component-graph/component-graph-executor.test.ts +0 -41
- package/src/route-renderer/component-graph/component-graph.test.ts +0 -63
- package/src/route-renderer/component-graph/component-marker.test.ts +0 -73
- package/src/route-renderer/component-graph/marker-graph-resolver.test.ts +0 -135
- package/src/route-renderer/orchestration/integration-renderer.test.ts +0 -936
- package/src/route-renderer/orchestration/render-execution.service.test.ts +0 -97
- package/src/route-renderer/orchestration/render-preparation.service.test.ts +0 -235
- package/src/route-renderer/page-loading/dependency-resolver.test.ts +0 -345
- package/src/route-renderer/page-loading/page-module-loader.test.ts +0 -96
- package/src/router/client/navigation-coordinator.test.ts +0 -237
- package/src/router/server/fs-router-scanner.test.ts +0 -83
- package/src/router/server/fs-router.test.ts +0 -214
- package/src/services/assets/asset-processing-service/asset-processing.service.test.ts +0 -385
- package/src/services/assets/asset-processing-service/asset.factory.test.ts +0 -63
- package/src/services/assets/asset-processing-service/browser-runtime-asset.factory.test.ts +0 -72
- package/src/services/assets/asset-processing-service/browser-runtime-entry.factory.test.ts +0 -67
- package/src/services/assets/asset-processing-service/processors/base/base-processor.test.ts +0 -59
- package/src/services/assets/asset-processing-service/processors/script/file-script.processor.test.ts +0 -286
- package/src/services/assets/asset-processing-service/processors/script/node-module-script.processor.test.ts +0 -227
- package/src/services/assets/asset-processing-service/processors/stylesheet/content-stylesheet.processor.test.ts +0 -199
- package/src/services/assets/browser-bundle.service.test.ts +0 -36
- package/src/services/cache/memory-cache-store.test.ts +0 -225
- package/src/services/cache/page-cache-service.test.ts +0 -175
- package/src/services/cache/page-request-cache-coordinator.service.test.ts +0 -79
- package/src/services/html/html-rewriter-provider.service.test.ts +0 -183
- package/src/services/html/html-transformer.service.test.ts +0 -378
- package/src/services/invalidation/development-invalidation.service.test.ts +0 -77
- package/src/services/module-loading/page-module-import.service.test.ts +0 -253
- package/src/services/module-loading/server-loader.service.test.ts +0 -161
- package/src/services/module-loading/server-module-transpiler.service.test.ts +0 -115
- package/src/services/runtime-manifest/node-runtime-manifest.service.test.ts +0 -95
- package/src/services/validation/schema-validation-service.test.ts +0 -223
- package/src/static-site-generator/static-site-generator.test.ts +0 -307
- package/src/utils/deep-merge.test.ts +0 -114
- package/src/utils/invariant.test.ts +0 -22
- package/src/utils/path-utils.test.ts +0 -15
- package/src/utils/server-utils.test.ts +0 -38
- package/src/watchers/project-watcher.integration.test.ts +0 -337
- package/src/watchers/project-watcher.test.ts +0 -678
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { type Server as NodeHttpServer } from 'node:http';
|
|
2
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
3
|
+
import type { ApiHandler, ErrorHandler, StaticRoute } from '../../public-types.js';
|
|
4
|
+
import { SharedServerAdapter } from '../shared/server-adapter.js';
|
|
5
|
+
import type { ServerAdapterResult } from '../abstract/server-adapter.js';
|
|
6
|
+
export type NodeServerInstance = NodeHttpServer;
|
|
7
|
+
export type NodeServeAdapterServerOptions = {
|
|
8
|
+
port?: number;
|
|
9
|
+
hostname?: string;
|
|
10
|
+
[key: string]: unknown;
|
|
11
|
+
};
|
|
12
|
+
export interface NodeServerAdapterParams {
|
|
13
|
+
appConfig: EcoPagesAppConfig;
|
|
14
|
+
runtimeOrigin: string;
|
|
15
|
+
serveOptions: NodeServeAdapterServerOptions;
|
|
16
|
+
apiHandlers?: ApiHandler[];
|
|
17
|
+
staticRoutes?: StaticRoute[];
|
|
18
|
+
errorHandler?: ErrorHandler;
|
|
19
|
+
options?: {
|
|
20
|
+
watch?: boolean;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export interface NodeServerAdapterResult extends ServerAdapterResult {
|
|
24
|
+
completeInitialization: (server: NodeServerInstance) => Promise<void>;
|
|
25
|
+
handleRequest: (request: Request) => Promise<Response>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Node.js HTTP server adapter for the Ecopages runtime.
|
|
29
|
+
*
|
|
30
|
+
* `NodeServerAdapter` bridges the Node.js `http` module and the Ecopages
|
|
31
|
+
* `SharedServerAdapter` abstraction, translating between Node's
|
|
32
|
+
* `IncomingMessage`/`ServerResponse` API and the platform-agnostic Web
|
|
33
|
+
* `Request`/`Response` model.
|
|
34
|
+
*
|
|
35
|
+
* Lifecycle:
|
|
36
|
+
* 1. `createAdapter()` — calls `initialize()` and returns the public adapter result.
|
|
37
|
+
* 2. `completeInitialization(server)` — called once the HTTP server is listening.
|
|
38
|
+
* Conditionally wires HMR, WebSocket upgrades, and the file watcher when
|
|
39
|
+
* `options.watch` is `true`.
|
|
40
|
+
* 3. `handleRequest(request)` — delegates to `handleSharedRequest` for routing;
|
|
41
|
+
* intercepts `ClientAbortError` to return 499 instead of 500.
|
|
42
|
+
* 4. `buildStatic()` — spins up an ephemeral runtime server, generates all static
|
|
43
|
+
* pages against it, then tears it down.
|
|
44
|
+
*
|
|
45
|
+
* @see SharedServerAdapter for routing, caching and response handler logic.
|
|
46
|
+
*/
|
|
47
|
+
export declare class NodeServerAdapter extends SharedServerAdapter<NodeServerAdapterParams, NodeServerAdapterResult> {
|
|
48
|
+
private serverInstance;
|
|
49
|
+
private initialized;
|
|
50
|
+
private apiHandlers;
|
|
51
|
+
private staticRoutes;
|
|
52
|
+
private errorHandler?;
|
|
53
|
+
private previewServer;
|
|
54
|
+
private bridge;
|
|
55
|
+
private hmrManager;
|
|
56
|
+
constructor(options: NodeServerAdapterParams);
|
|
57
|
+
/**
|
|
58
|
+
* Prepares the adapter for use.
|
|
59
|
+
*
|
|
60
|
+
* Order is intentional:
|
|
61
|
+
* 1. **Loaders** are registered first so processors and integrations can
|
|
62
|
+
* reference loader-provided file types in their own plugins.
|
|
63
|
+
* 2. **Public dir** is copied before any build so static assets are in `distDir`
|
|
64
|
+
* before the first request arrives.
|
|
65
|
+
* 3. **Plugins** (processors, then integrations) are set up after the public dir
|
|
66
|
+
* is in place so they can safely reference dist-relative paths.
|
|
67
|
+
* 4. **Router** is initialised last because it may depend on files written by
|
|
68
|
+
* processors during their `setup()` calls.
|
|
69
|
+
*/
|
|
70
|
+
initialize(): Promise<void>;
|
|
71
|
+
getServerOptions(): NodeServeAdapterServerOptions;
|
|
72
|
+
buildStatic(options?: {
|
|
73
|
+
preview?: boolean;
|
|
74
|
+
}): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Converts a Node.js `IncomingMessage` into a Web API `Request`.
|
|
77
|
+
*
|
|
78
|
+
* Multi-value headers (e.g. `set-cookie`) are appended individually so no
|
|
79
|
+
* value is silently dropped.
|
|
80
|
+
*
|
|
81
|
+
* For methods that carry a body (`POST`, `PUT`, `PATCH`, …), the raw
|
|
82
|
+
* `IncomingMessage` stream is wrapped in a `ReadableStream` rather than
|
|
83
|
+
* cast directly to `BodyInit`. See the inline doc block inside the `if`
|
|
84
|
+
* branch for the rationale (client-abort handling).
|
|
85
|
+
*
|
|
86
|
+
* `duplex: 'half'` is required by the `fetch` spec when a streaming body is
|
|
87
|
+
* provided — without it Node.js 18+ throws a `TypeError`.
|
|
88
|
+
*/
|
|
89
|
+
private createWebRequest;
|
|
90
|
+
/**
|
|
91
|
+
* Writes a Web `Response` back to a Node.js `ServerResponse`.
|
|
92
|
+
*
|
|
93
|
+
* The entire body is buffered via `arrayBuffer()` before writing. This is
|
|
94
|
+
* intentional for the current use-case (SSR pages and API routes), where
|
|
95
|
+
* responses are typically small and fully materialised. Streaming responses
|
|
96
|
+
* are not yet supported.
|
|
97
|
+
*/
|
|
98
|
+
private sendNodeResponse;
|
|
99
|
+
/**
|
|
100
|
+
* Starts an ephemeral HTTP server used *only* during a static site generation
|
|
101
|
+
* run.
|
|
102
|
+
*
|
|
103
|
+
* Static generation works by having the `StaticSiteGenerator` issue real HTTP
|
|
104
|
+
* requests to a live server for each route, capturing the rendered HTML. This
|
|
105
|
+
* approach reuses the normal request pipeline (middleware, caching, API
|
|
106
|
+
* handlers) without any special-casing for the build path.
|
|
107
|
+
*
|
|
108
|
+
* The server is torn down immediately after generation completes via
|
|
109
|
+
* `stopBuildRuntimeServer`, so it never overlaps with the actual dev/prod server.
|
|
110
|
+
*/
|
|
111
|
+
private startBuildRuntimeServer;
|
|
112
|
+
/**
|
|
113
|
+
* Gracefully shuts down the ephemeral build runtime server.
|
|
114
|
+
*
|
|
115
|
+
* `closeAllConnections()` is called *before* `close()` because `server.close()`
|
|
116
|
+
* only stops accepting new connections — it waits for existing keep-alive
|
|
117
|
+
* connections to finish naturally, which can stall the build indefinitely.
|
|
118
|
+
* `closeAllConnections()` force-closes any lingering sockets immediately so
|
|
119
|
+
* the `close()` callback fires promptly.
|
|
120
|
+
*
|
|
121
|
+
* The `NodeClientBridge` heartbeat is also destroyed here so its `setInterval`
|
|
122
|
+
* does not prevent the Node.js process from exiting cleanly after the build.
|
|
123
|
+
*/
|
|
124
|
+
private stopBuildRuntimeServer;
|
|
125
|
+
createAdapter(): Promise<NodeServerAdapterResult>;
|
|
126
|
+
/**
|
|
127
|
+
* Handles a single incoming Web `Request` and returns a Web `Response`.
|
|
128
|
+
*
|
|
129
|
+
* Delegates to `handleSharedRequest` for all routing, caching, and response
|
|
130
|
+
* handler logic. The only Node-specific concern here is translating a
|
|
131
|
+
* `ClientAbortError` — which the body `ReadableStream` raises when the
|
|
132
|
+
* underlying socket closes early — into a 499 response so it does not
|
|
133
|
+
* incorrectly surface as a 500 in application logs.
|
|
134
|
+
*/
|
|
135
|
+
handleRequest(_request: Request): Promise<Response>;
|
|
136
|
+
/**
|
|
137
|
+
* Called once the HTTP server is bound and listening.
|
|
138
|
+
*
|
|
139
|
+
* When `options.watch` is `true` this method wires the full HMR pipeline:
|
|
140
|
+
* - A `WebSocketServer` is attached to the existing HTTP server via the
|
|
141
|
+
* `upgrade` event (no separate port needed).
|
|
142
|
+
* - `NodeClientBridge` tracks active WebSocket connections and handles
|
|
143
|
+
* broadcast + heartbeat cleanup.
|
|
144
|
+
* - `NodeHmrManager` watches the filesystem and triggers incremental esbuild
|
|
145
|
+
* rebuilds, notifying connected clients via the bridge.
|
|
146
|
+
* - Shared watcher bootstrapping listens for route-level file changes and
|
|
147
|
+
* refreshes the router and response handlers when pages are added or removed.
|
|
148
|
+
*
|
|
149
|
+
* WebSocket upgrade requests that do not target `/_hmr` are rejected with an
|
|
150
|
+
* immediate socket destroy to prevent unhandled upgrade leaks.
|
|
151
|
+
*/
|
|
152
|
+
completeInitialization(_server: NodeServerInstance): Promise<void>;
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Factory function that creates and fully initialises a `NodeServerAdapter`.
|
|
156
|
+
*
|
|
157
|
+
* `runtimeOrigin` is derived from `serveOptions` when not explicitly provided,
|
|
158
|
+
* so callers only need to set it when the server is behind a reverse proxy that
|
|
159
|
+
* changes the effective host or port.
|
|
160
|
+
*/
|
|
161
|
+
export declare function createNodeServerAdapter(params: NodeServerAdapterParams): Promise<NodeServerAdapterResult>;
|
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { createServer } from "node:http";
|
|
2
|
+
import { appLogger } from "../../global/app-logger.js";
|
|
3
|
+
import { NodeClientBridge } from "./node-client-bridge.js";
|
|
4
|
+
import { NodeHmrManager } from "./node-hmr-manager.js";
|
|
5
|
+
import { StaticSiteGenerator } from "../../static-site-generator/static-site-generator.js";
|
|
6
|
+
import { SharedServerAdapter } from "../shared/server-adapter.js";
|
|
7
|
+
import { ServerStaticBuilder } from "../shared/server-static-builder.js";
|
|
8
|
+
import {
|
|
9
|
+
bindSharedRuntimeHmrManager,
|
|
10
|
+
initializeSharedRuntimePlugins,
|
|
11
|
+
installSharedRuntimeBuildExecutor,
|
|
12
|
+
prepareSharedRuntimePublicDir,
|
|
13
|
+
startSharedProjectWatching
|
|
14
|
+
} from "../shared/runtime-bootstrap.js";
|
|
15
|
+
import { NodeStaticContentServer } from "./static-content-server.js";
|
|
16
|
+
class ClientAbortError extends Error {
|
|
17
|
+
constructor() {
|
|
18
|
+
super("Client closed the request");
|
|
19
|
+
this.name = "ClientAbortError";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
class NodeServerAdapter extends SharedServerAdapter {
|
|
23
|
+
serverInstance = null;
|
|
24
|
+
initialized = false;
|
|
25
|
+
apiHandlers;
|
|
26
|
+
staticRoutes;
|
|
27
|
+
errorHandler;
|
|
28
|
+
previewServer = null;
|
|
29
|
+
bridge = null;
|
|
30
|
+
hmrManager = null;
|
|
31
|
+
constructor(options) {
|
|
32
|
+
super(options);
|
|
33
|
+
this.apiHandlers = options.apiHandlers || [];
|
|
34
|
+
this.staticRoutes = options.staticRoutes || [];
|
|
35
|
+
this.errorHandler = options.errorHandler;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Prepares the adapter for use.
|
|
39
|
+
*
|
|
40
|
+
* Order is intentional:
|
|
41
|
+
* 1. **Loaders** are registered first so processors and integrations can
|
|
42
|
+
* reference loader-provided file types in their own plugins.
|
|
43
|
+
* 2. **Public dir** is copied before any build so static assets are in `distDir`
|
|
44
|
+
* before the first request arrives.
|
|
45
|
+
* 3. **Plugins** (processors, then integrations) are set up after the public dir
|
|
46
|
+
* is in place so they can safely reference dist-relative paths.
|
|
47
|
+
* 4. **Router** is initialised last because it may depend on files written by
|
|
48
|
+
* processors during their `setup()` calls.
|
|
49
|
+
*/
|
|
50
|
+
async initialize() {
|
|
51
|
+
installSharedRuntimeBuildExecutor(this.appConfig, {
|
|
52
|
+
development: this.options?.watch === true
|
|
53
|
+
});
|
|
54
|
+
prepareSharedRuntimePublicDir(this.appConfig);
|
|
55
|
+
await initializeSharedRuntimePlugins({
|
|
56
|
+
appConfig: this.appConfig,
|
|
57
|
+
runtimeOrigin: this.runtimeOrigin,
|
|
58
|
+
hmrManager: this.hmrManager ?? void 0
|
|
59
|
+
});
|
|
60
|
+
await this.initializeSharedRouteHandling({
|
|
61
|
+
staticRoutes: this.staticRoutes,
|
|
62
|
+
hmrManager: this.hmrManager ?? void 0
|
|
63
|
+
});
|
|
64
|
+
this.staticSiteGenerator = new StaticSiteGenerator({ appConfig: this.appConfig });
|
|
65
|
+
this.staticBuilder = new ServerStaticBuilder({
|
|
66
|
+
appConfig: this.appConfig,
|
|
67
|
+
staticSiteGenerator: this.staticSiteGenerator,
|
|
68
|
+
serveOptions: this.serveOptions,
|
|
69
|
+
apiHandlers: this.apiHandlers
|
|
70
|
+
});
|
|
71
|
+
this.initialized = true;
|
|
72
|
+
}
|
|
73
|
+
getServerOptions() {
|
|
74
|
+
return {
|
|
75
|
+
...this.serveOptions
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
async buildStatic(options) {
|
|
79
|
+
if (!this.initialized) {
|
|
80
|
+
await this.initialize();
|
|
81
|
+
}
|
|
82
|
+
const buildServer = await this.startBuildRuntimeServer();
|
|
83
|
+
try {
|
|
84
|
+
await this.staticBuilder.build(
|
|
85
|
+
{ preview: false },
|
|
86
|
+
{
|
|
87
|
+
router: this.router,
|
|
88
|
+
routeRendererFactory: this.routeRendererFactory,
|
|
89
|
+
staticRoutes: this.staticRoutes
|
|
90
|
+
}
|
|
91
|
+
);
|
|
92
|
+
} finally {
|
|
93
|
+
await this.stopBuildRuntimeServer(buildServer);
|
|
94
|
+
}
|
|
95
|
+
if (!options?.preview) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (this.previewServer) {
|
|
99
|
+
await this.previewServer.stop();
|
|
100
|
+
}
|
|
101
|
+
this.previewServer = new NodeStaticContentServer({
|
|
102
|
+
appConfig: this.appConfig,
|
|
103
|
+
options: {
|
|
104
|
+
hostname: this.serveOptions.hostname,
|
|
105
|
+
port: Number(this.serveOptions.port || 3e3)
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
await this.previewServer.start();
|
|
109
|
+
const previewHostname = this.serveOptions.hostname || "localhost";
|
|
110
|
+
const previewPort = this.serveOptions.port || 3e3;
|
|
111
|
+
appLogger.info(`Preview running at http://${previewHostname}:${previewPort}`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Converts a Node.js `IncomingMessage` into a Web API `Request`.
|
|
115
|
+
*
|
|
116
|
+
* Multi-value headers (e.g. `set-cookie`) are appended individually so no
|
|
117
|
+
* value is silently dropped.
|
|
118
|
+
*
|
|
119
|
+
* For methods that carry a body (`POST`, `PUT`, `PATCH`, …), the raw
|
|
120
|
+
* `IncomingMessage` stream is wrapped in a `ReadableStream` rather than
|
|
121
|
+
* cast directly to `BodyInit`. See the inline doc block inside the `if`
|
|
122
|
+
* branch for the rationale (client-abort handling).
|
|
123
|
+
*
|
|
124
|
+
* `duplex: 'half'` is required by the `fetch` spec when a streaming body is
|
|
125
|
+
* provided — without it Node.js 18+ throws a `TypeError`.
|
|
126
|
+
*/
|
|
127
|
+
createWebRequest(req) {
|
|
128
|
+
const url = new URL(req.url ?? "/", this.runtimeOrigin);
|
|
129
|
+
const headers = new Headers();
|
|
130
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
131
|
+
if (Array.isArray(value)) {
|
|
132
|
+
for (const item of value) {
|
|
133
|
+
headers.append(key, item);
|
|
134
|
+
}
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (value !== void 0) {
|
|
138
|
+
headers.set(key, value);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
const method = (req.method ?? "GET").toUpperCase();
|
|
142
|
+
const requestInit = {
|
|
143
|
+
method,
|
|
144
|
+
headers
|
|
145
|
+
};
|
|
146
|
+
if (method !== "GET" && method !== "HEAD") {
|
|
147
|
+
const body = new ReadableStream({
|
|
148
|
+
start(controller) {
|
|
149
|
+
req.on("data", (chunk) => controller.enqueue(chunk));
|
|
150
|
+
req.once("end", () => controller.close());
|
|
151
|
+
req.once("aborted", () => {
|
|
152
|
+
controller.error(new ClientAbortError());
|
|
153
|
+
});
|
|
154
|
+
req.once("error", (err) => {
|
|
155
|
+
const isClientAbort = err.code === "ECONNRESET";
|
|
156
|
+
controller.error(isClientAbort ? new ClientAbortError() : err);
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
cancel() {
|
|
160
|
+
req.destroy();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
requestInit.body = body;
|
|
164
|
+
requestInit.duplex = "half";
|
|
165
|
+
}
|
|
166
|
+
return new Request(url, requestInit);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Writes a Web `Response` back to a Node.js `ServerResponse`.
|
|
170
|
+
*
|
|
171
|
+
* The entire body is buffered via `arrayBuffer()` before writing. This is
|
|
172
|
+
* intentional for the current use-case (SSR pages and API routes), where
|
|
173
|
+
* responses are typically small and fully materialised. Streaming responses
|
|
174
|
+
* are not yet supported.
|
|
175
|
+
*/
|
|
176
|
+
async sendNodeResponse(res, response) {
|
|
177
|
+
res.statusCode = response.status;
|
|
178
|
+
response.headers.forEach((value, key) => {
|
|
179
|
+
res.setHeader(key, value);
|
|
180
|
+
});
|
|
181
|
+
if (!response.body) {
|
|
182
|
+
res.end();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
186
|
+
res.end(body);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Starts an ephemeral HTTP server used *only* during a static site generation
|
|
190
|
+
* run.
|
|
191
|
+
*
|
|
192
|
+
* Static generation works by having the `StaticSiteGenerator` issue real HTTP
|
|
193
|
+
* requests to a live server for each route, capturing the rendered HTML. This
|
|
194
|
+
* approach reuses the normal request pipeline (middleware, caching, API
|
|
195
|
+
* handlers) without any special-casing for the build path.
|
|
196
|
+
*
|
|
197
|
+
* The server is torn down immediately after generation completes via
|
|
198
|
+
* `stopBuildRuntimeServer`, so it never overlaps with the actual dev/prod server.
|
|
199
|
+
*/
|
|
200
|
+
async startBuildRuntimeServer() {
|
|
201
|
+
const hostname = String(this.serveOptions.hostname || "localhost");
|
|
202
|
+
const port = Number(this.serveOptions.port || 3e3);
|
|
203
|
+
const server = createServer(async (req, res) => {
|
|
204
|
+
try {
|
|
205
|
+
const webRequest = this.createWebRequest(req);
|
|
206
|
+
const response = await this.handleRequest(webRequest);
|
|
207
|
+
await this.sendNodeResponse(res, response);
|
|
208
|
+
} catch (error) {
|
|
209
|
+
appLogger.error("Node static build runtime request failed", error);
|
|
210
|
+
res.statusCode = 500;
|
|
211
|
+
res.end("Internal Server Error");
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
await new Promise((resolve, reject) => {
|
|
215
|
+
server.once("error", reject);
|
|
216
|
+
server.listen(port, hostname, () => {
|
|
217
|
+
server.off("error", reject);
|
|
218
|
+
resolve();
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
this.serverInstance = server;
|
|
222
|
+
appLogger.info(`Server running at http://${hostname}:${port}`);
|
|
223
|
+
return server;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Gracefully shuts down the ephemeral build runtime server.
|
|
227
|
+
*
|
|
228
|
+
* `closeAllConnections()` is called *before* `close()` because `server.close()`
|
|
229
|
+
* only stops accepting new connections — it waits for existing keep-alive
|
|
230
|
+
* connections to finish naturally, which can stall the build indefinitely.
|
|
231
|
+
* `closeAllConnections()` force-closes any lingering sockets immediately so
|
|
232
|
+
* the `close()` callback fires promptly.
|
|
233
|
+
*
|
|
234
|
+
* The `NodeClientBridge` heartbeat is also destroyed here so its `setInterval`
|
|
235
|
+
* does not prevent the Node.js process from exiting cleanly after the build.
|
|
236
|
+
*/
|
|
237
|
+
async stopBuildRuntimeServer(server) {
|
|
238
|
+
await new Promise((resolve, reject) => {
|
|
239
|
+
server.close((error) => {
|
|
240
|
+
if (error) {
|
|
241
|
+
reject(error);
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
resolve();
|
|
245
|
+
});
|
|
246
|
+
server.closeAllConnections();
|
|
247
|
+
});
|
|
248
|
+
if (this.serverInstance === server) {
|
|
249
|
+
this.serverInstance = null;
|
|
250
|
+
}
|
|
251
|
+
this.bridge?.destroy();
|
|
252
|
+
this.bridge = null;
|
|
253
|
+
}
|
|
254
|
+
async createAdapter() {
|
|
255
|
+
await this.initialize();
|
|
256
|
+
return {
|
|
257
|
+
getServerOptions: this.getServerOptions.bind(this),
|
|
258
|
+
buildStatic: this.buildStatic.bind(this),
|
|
259
|
+
completeInitialization: this.completeInitialization.bind(this),
|
|
260
|
+
handleRequest: this.handleRequest.bind(this)
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Handles a single incoming Web `Request` and returns a Web `Response`.
|
|
265
|
+
*
|
|
266
|
+
* Delegates to `handleSharedRequest` for all routing, caching, and response
|
|
267
|
+
* handler logic. The only Node-specific concern here is translating a
|
|
268
|
+
* `ClientAbortError` — which the body `ReadableStream` raises when the
|
|
269
|
+
* underlying socket closes early — into a 499 response so it does not
|
|
270
|
+
* incorrectly surface as a 500 in application logs.
|
|
271
|
+
*/
|
|
272
|
+
async handleRequest(_request) {
|
|
273
|
+
if (!this.initialized) {
|
|
274
|
+
throw new Error("Node server adapter is not initialized. Call createAdapter() first.");
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
return await this.handleSharedRequest(_request, {
|
|
278
|
+
apiHandlers: this.apiHandlers,
|
|
279
|
+
errorHandler: this.errorHandler,
|
|
280
|
+
serverInstance: this.serverInstance,
|
|
281
|
+
hmrManager: this.hmrManager
|
|
282
|
+
});
|
|
283
|
+
} catch (error) {
|
|
284
|
+
if (error instanceof ClientAbortError) {
|
|
285
|
+
return new Response(null, { status: 499 });
|
|
286
|
+
}
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Called once the HTTP server is bound and listening.
|
|
292
|
+
*
|
|
293
|
+
* When `options.watch` is `true` this method wires the full HMR pipeline:
|
|
294
|
+
* - A `WebSocketServer` is attached to the existing HTTP server via the
|
|
295
|
+
* `upgrade` event (no separate port needed).
|
|
296
|
+
* - `NodeClientBridge` tracks active WebSocket connections and handles
|
|
297
|
+
* broadcast + heartbeat cleanup.
|
|
298
|
+
* - `NodeHmrManager` watches the filesystem and triggers incremental esbuild
|
|
299
|
+
* rebuilds, notifying connected clients via the bridge.
|
|
300
|
+
* - Shared watcher bootstrapping listens for route-level file changes and
|
|
301
|
+
* refreshes the router and response handlers when pages are added or removed.
|
|
302
|
+
*
|
|
303
|
+
* WebSocket upgrade requests that do not target `/_hmr` are rejected with an
|
|
304
|
+
* immediate socket destroy to prevent unhandled upgrade leaks.
|
|
305
|
+
*/
|
|
306
|
+
async completeInitialization(_server) {
|
|
307
|
+
this.serverInstance = _server;
|
|
308
|
+
if (this.options?.watch) {
|
|
309
|
+
const { WebSocketServer } = await import("ws");
|
|
310
|
+
const wss = new WebSocketServer({ noServer: true });
|
|
311
|
+
this.bridge = new NodeClientBridge();
|
|
312
|
+
this.hmrManager = new NodeHmrManager({ appConfig: this.appConfig, bridge: this.bridge });
|
|
313
|
+
this.hmrManager.setEnabled(true);
|
|
314
|
+
await this.hmrManager.buildRuntime();
|
|
315
|
+
_server.on("upgrade", (req, socket, head) => {
|
|
316
|
+
const url = new URL(req.url ?? "/", this.runtimeOrigin);
|
|
317
|
+
if (url.pathname === "/_hmr") {
|
|
318
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
|
319
|
+
this.bridge.subscribe(ws);
|
|
320
|
+
ws.on("close", () => this.bridge.unsubscribe(ws));
|
|
321
|
+
ws.on("error", (err) => appLogger.error("[HMR] WebSocket error:", err));
|
|
322
|
+
});
|
|
323
|
+
} else {
|
|
324
|
+
socket.destroy();
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
bindSharedRuntimeHmrManager(this.appConfig, this.hmrManager);
|
|
328
|
+
this.configureSharedResponseHandlers(this.staticRoutes, this.hmrManager);
|
|
329
|
+
await startSharedProjectWatching({
|
|
330
|
+
appConfig: this.appConfig,
|
|
331
|
+
refreshRouterRoutesCallback: this.createSharedWatchRefreshCallback({
|
|
332
|
+
staticRoutes: this.staticRoutes,
|
|
333
|
+
hmrManager: this.hmrManager
|
|
334
|
+
}),
|
|
335
|
+
hmrManager: this.hmrManager,
|
|
336
|
+
bridge: this.bridge
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
appLogger.debug("Node server adapter initialization completed", {
|
|
340
|
+
apiHandlers: this.apiHandlers.length,
|
|
341
|
+
staticRoutes: this.staticRoutes.length,
|
|
342
|
+
hasErrorHandler: !!this.errorHandler,
|
|
343
|
+
hmrEnabled: !!this.hmrManager?.isEnabled()
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
async function createNodeServerAdapter(params) {
|
|
348
|
+
const runtimeOrigin = params.runtimeOrigin ?? `http://${params.serveOptions.hostname || "localhost"}:${params.serveOptions.port || 3e3}`;
|
|
349
|
+
const adapter = new NodeServerAdapter({
|
|
350
|
+
...params,
|
|
351
|
+
runtimeOrigin
|
|
352
|
+
});
|
|
353
|
+
return adapter.createAdapter();
|
|
354
|
+
}
|
|
355
|
+
export {
|
|
356
|
+
NodeServerAdapter,
|
|
357
|
+
createNodeServerAdapter
|
|
358
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Server as NodeHttpServer } from 'node:http';
|
|
2
|
+
import type { EcoPagesAppConfig } from '../../internal-types.js';
|
|
3
|
+
type NodeStaticContentServerOptions = {
|
|
4
|
+
hostname?: string;
|
|
5
|
+
port?: number;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Serves prebuilt static Ecopages output through Node's HTTP server.
|
|
9
|
+
*
|
|
10
|
+
* @remarks
|
|
11
|
+
* This server is used by the Node preview/build path once the app has already
|
|
12
|
+
* emitted its static output. It intentionally stays small: path sanitization,
|
|
13
|
+
* content-type selection, optional gzip serving, and 404 handling.
|
|
14
|
+
*/
|
|
15
|
+
export declare class NodeStaticContentServer {
|
|
16
|
+
private readonly appConfig;
|
|
17
|
+
private readonly options;
|
|
18
|
+
private server;
|
|
19
|
+
/**
|
|
20
|
+
* Creates the Node static-content server for one built app output directory.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ appConfig, options }: {
|
|
23
|
+
appConfig: EcoPagesAppConfig;
|
|
24
|
+
options?: NodeStaticContentServerOptions;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Returns whether the given content type should be served from a pre-gzipped
|
|
28
|
+
* companion file when available.
|
|
29
|
+
*/
|
|
30
|
+
private shouldServeGzip;
|
|
31
|
+
/**
|
|
32
|
+
* Normalizes a request pathname and rejects directory traversal attempts.
|
|
33
|
+
*/
|
|
34
|
+
private sanitizePath;
|
|
35
|
+
/**
|
|
36
|
+
* Writes one HTTP response with the provided headers and optional body.
|
|
37
|
+
*/
|
|
38
|
+
private sendResponse;
|
|
39
|
+
/**
|
|
40
|
+
* Serves the generated 404 page when present, or a plain-text fallback.
|
|
41
|
+
*/
|
|
42
|
+
private sendNotFoundPage;
|
|
43
|
+
/**
|
|
44
|
+
* Serves one concrete file path, honoring gzip and HEAD semantics.
|
|
45
|
+
*/
|
|
46
|
+
private serveFile;
|
|
47
|
+
/**
|
|
48
|
+
* Handles one incoming Node HTTP request against the built static output tree.
|
|
49
|
+
*/
|
|
50
|
+
private handleRequest;
|
|
51
|
+
/**
|
|
52
|
+
* Starts the static preview server.
|
|
53
|
+
*/
|
|
54
|
+
start(): Promise<NodeHttpServer>;
|
|
55
|
+
/**
|
|
56
|
+
* Stops the static preview server and optionally closes active connections.
|
|
57
|
+
*/
|
|
58
|
+
stop(force?: boolean): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
export {};
|