Middleware
@esmx/core exposes a small set of connect-style middleware helpers used to serve a module's static assets (the built dist/client output) with correct cache headers. These are what esmx.middleware is built from, and you can compose them directly when wiring your own HTTP server.
Middleware
A connect-style middleware: it receives the Node request and response plus a next callback, and either handles the request or calls next() to pass control on. It is compatible with http, Express, Koa (via adapters), and most Node servers.
createMiddleware(esmx)
Creates the middleware that serves static resources for every module in the Esmx instance. It:
- builds a static-file handler per module from the module configuration,
- applies cache control per request, and
- serves content-hashed (immutable) files with long-lived caching.
mergeMiddlewares(middlewares)
Composes an array of middlewares into a single middleware, running them in order until one handles the request or the chain ends (calling the outer next). Useful for combining createMiddleware's output with your own handlers.
isImmutableFile(filename)
Returns true when a file path matches Esmx's content-hashed (immutable) asset pattern — i.e. safe to serve with Cache-Control: public, max-age=31536000, immutable. createMiddleware uses it internally to decide the cache policy for each asset.
Related
- Esmx — the core class whose
middlewareis composed from these helpers - RenderContext — how rendered HTML references the assets these serve