Deployment
Build TypeScript before productionhile start. In development, hile start --dev imports src/**/*.boot.ts; in production it imports dist/**/*.boot.js.
Runtime And Lifecycle Notes
defineService(key, fn)registers a service factory and does not execute it.loadService(service)executes the factory on first call and returns the cached value afterwards.- The
shutdowncallback registers teardown functions; they run in LIFO order. - The container tracks dependencies when service factories call
loadService(). container.shutdown()triggers registered teardowns.@hile/bootstraploads env files first, setsNODE_ENV, imports auto-load packages, scans boot files, and installs exit hooks.@hile/logger.createLogger()returns{ logger, teardown }.@hile/ioredis.createRedis()waits forconnect.@hile/typeorm.createDataSource()initializes a TypeORMDataSource.
Runtime And Lifecycle Notes
HttpNextkeeps its internalHttpinstance private and exposes onlyuse(),load(), andstart().- Except for
cwd, constructor options are theHttpPropspassed unchanged to the sharedHttpinstance, including complete Koa options, bounded reverse-proxy trust, and router options. - Hile middleware and controllers run first; unmatched requests are passed to Next.js with the original Node request and response.
@hile/http-next/request-signalis the Next-free App Router entrypoint for reading the current request’s cancellation signal.- Concurrent requests, multiple
HttpNextinstances, and compatible package copies in one JavaScript realm share one storage identity while retaining isolated asynchronous contexts. Separate PM2 processes, Workers, or VM realms intentionally keep independent request signals. - Development mode is determined by
process.env.NODE_ENV === 'development'. - Controllers use
{cwd}/src/controllersin development and{cwd}/dist/controllersin production with prefix/-. - Required catch-all controllers use the same
[...name]final-segment convention as@hile/http; unmatched requests alone continue to Next.js. load(directory)explicitly loads an additional controller directory with the same fixed conventions.- Call
use()andload()beforestart(); configuration is frozen once startup begins. - Next.js exclusively owns
public/,distDir,/_next/static, RSC, Server Functions, andnext.config. start(onReady)calls readiness only after Next is prepared and the shared HTTP server is listening.- The returned async stop function first asks the shared HTTP server to stop accepting new connections, then waits for HTTP drain and Next runtime cleanup concurrently. It tracks and terminates upgraded connections, including development HMR WebSockets, because Node’s HTTP drain does not own their protocol lifecycle. Development shutdown also closes disposable HTTP/compiler connections, matching Next’s own development-server policy; production HTTP requests retain graceful drain behavior.
- Normal stop attempts HTTP, Next, and startup-loaded controller cleanup even when one side fails. One cleanup failure is rethrown directly and multiple cleanup failures are reported together. Startup rollback also attempts every acquired cleanup, then preserves the original startup error.
Production Checklist
- Register every server/client close function with
shutdown. - Load controllers before
listen()in new code. - Size Redis lock TTLs for the actual job duration.
- Monitor queue DLQs and idempotency release failures.
- Keep DB constraints or provider idempotency keys for irreversible side effects.