Support host-owned Node embedding without an HTTP listener #526
Replies: 1 comment
|
Thanks for the detailed writeup. Good news: on 2.0 (current nightlies), the core of this already exists. For non-HTTP programmatic embedding with explicit dependency injection ( Two parts of your request are real gaps we're treating as open questions rather than bugs: exported TypeScript types for the |
Uh oh!
There was an error while loading. Please reload this page.
Problem
Some Node hosts own the HTTP listener, request admission, process lifecycle, and shutdown ordering. In that environment Flue needs to run as an in-process Fetch application rather than as the process entrypoint.
The generated Node artifact already contains the useful lower-level API:
However,
flue build --target nodeappends an unconditional top-level call tostartFlueNodeServer(...)and installs signal handlers. Importingserver.mjstherefore starts a second listener. A host application currently has to post-process generated output to remove that startup tail. That is intentionally brittle and cannot be a supported production integration.There is a related composition problem: authored
app.ts,db.ts, channel, and agent modules are part of the generated module graph and may evaluate before application-specific dependencies can be supplied toloadFlueNodeApplication. A host that creates its database connection, bounded HTTP transport, logger, and application services must currently expose those process-lifetime dependencies through environment variables or an ambient global.Requested API
Could Flue support a first-class host-owned Node embedding mode with both:
loadFlueNodeApplicationwithout top-level startup or signal handlers. This might be a build option, or anapplication.mjsartifact plus the current thin standaloneserver.mjswrapper.Illustrative shape only:
The exact mechanism could instead be a generated factory or a typed authored-module context. The important properties are:
node server.mjsandflue devbehavior remain unchanged;fetch/stoptypes, without requiring imports from@flue/runtime/internal.This is for process-lifetime dependencies only. Per-turn principals, credentials, or ephemeral capabilities should remain separately scoped rather than becoming ambient application bindings.
Tested against
@flue/cli/@flue/runtime1.0.0-beta.9.All reactions