You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
v.1.8.13: Raw Bodies, Raw WebSockets, Live TLS Reload, Precompressed Assets & Runtime Fixes
req.rawBody: the request body exactly as received, before any parsing (JSON included), or null when there was none - what a webhook signature check needs. On every backend, bounded by the same body size limits; on the engine and Node it is the buffer the parser already had, on uWS one copy. raw({ type }) and text({ type }) join json() and urlencoded() as Express-idiom pass-throughs.
Raw WebSocket framing: app.websocket(path, handlers, { raw: true }) delivers every text frame to message as a string and every binary frame to binary as a Buffer, with no { event, data } envelope; socket.send(data, isBinary?) (new on every built-in adapter) or a string/Buffer returned from the handler is the reply frame. What a plain WebSocket client speaks - browsers calling WebSocket.send('hello'), load testers, non-Moro peers. Engine, ws and uWS adapters; Socket.IO speaks its own protocol and ignores raw. WebSocketNamespaceOptions is exported.
app.reloadTLS(ssl?): rotate the certificate and key on the running listener without a restart. With no argument the server.ssl files are re-read; with one, the given material (either shape) replaces them. The new pair is validated first (file readable, PEM parses, key matches certificate), so a bad or half-written file rejects and the current certificate keeps serving; connections already established are untouched. Native engine (@morojs/engine 1.1.8+, capabilities.tlsReload), Node https and HTTP/2; not uWebSockets.js.
server.ssl.watch: true | { debounceMs }: reload the certificate when its files change on disk. The directories are watched, so an ACME client's rename or a Kubernetes secret's symlink swap is caught; changes are debounced, unchanged bytes are ignored, and a failed reload is logged while the current certificate keeps serving. With clustering each worker watches and reloads its own listener.
staticFiles({ precompressed: true }): when app.js.br or app.js.gz sits beside app.js and the client accepts that encoding, the sidecar is served with the original's Content-Type, the matching Content-Encoding, Vary: Accept-Encoding and its own ETag (brotli preferred). A sidecar older than its source is ignored, so a replaced asset never ships a stale compressed body; a sidecar must resolve inside root (a symlink pointing outside is skipped); Range requests get the identity file.
RedisCacheAdapter accepts url (REDIS_URL) and client (an existing node-redis client), and gains close(), which quits a client the adapter created. CacheAdapter.close?() is an optional interface method; session storeOptions.url is typed.
Changed
Binary request bodies are no longer decoded to strings. application/octet-stream, image/*, audio/*, video/*, font/*, application/pdf, application/zip, protobuf, msgpack and every other non-text type reach the handler as a Buffer with the exact bytes (decoding them replaced every invalid sequence with U+FFFD and there was no way back). text/*, the JSON/XML/JavaScript/YAML families (including +json-style suffixes), anything declaring a charset, and a missing Content-Type still yield strings; JSON, urlencoded and multipart parse as before. Same rule on the Node, uWS and engine servers; documented under "Request bodies" in the API reference.
app.listen(port) on the native engine binds :: (dual-stack, every interface), exactly like Node's server.listen(port), with an IPv4-any fallback on hosts without IPv6. Previously it bound 0.0.0.0 only, so a client resolving localhost to ::1 first was refused. An explicit host is honoured as before; the server handle's address() reports the family.
performance.clustering.workers: 'auto' counts the CPUs and memory the process may actually use: a cgroup v2 or v1 CPU quota (docker run --cpus, a Kubernetes CPU limit), then os.availableParallelism() (which honours --cpuset-cpus), then os.cpus(); memory likewise from memory.max / memory.limit_in_bytes when below the host total. A 96-thread host pinned to 32 cores now starts 32 workers, not 96. The same probe drives uWS clustering and the worker-thread pool.
Static files: the mime table covers .webp, .avif, .mjs/.cjs, .wasm, .map, .webmanifest, .otf, .md, .csv, .yaml, .jsonld, .xhtml, common audio/video and archive types (.webp was application/octet-stream). Compressible bodies at or below the streaming threshold go out through res.send(), so performance.compression and the compression middleware now apply to text assets as they do to handler responses; binary, ranged and streamed bodies are unchanged.
RedisCacheAdapter targets node-redis 4+ (it was written against the v3 API: createClient({ host, port }), setex, no connect(), so on any current redis package every command failed with a closed client). The client is connected before the first command, every method awaits initialisation instead of racing the import, TTLs use SET ... PX so sub-second values work, clear() scans and deletes only this adapter's prefixed keys instead of FLUSHDB, and the keyPrefix (default moro:cache:) is actually applied - it was passed as an option node-redis never read. node-redis 3 is no longer supported.
A second createApp() in the same process that passes its own options now logs at ERROR naming the ignored keys. Configuration stays one-per-process: the first createApp() locks it and later apps share it, which previously happened silently (an app asking for port 8081 with TLS booted on the first app's port, plain).
When server.ssl is configured and the native engine fails to initialise, the fallback to Node https is logged at ERROR rather than WARN, so a deployment tuned for the engine cannot quietly run on a different server.
Fixed
TLS configured with file paths (server.ssl.keyFile/certFile, or key_file_name/cert_file_name) never reached the native engine. The normalised config was handed to serve() with the framework's own field names, the engine threw ssl requires both a key ... and a certificate, and the app fell back to Node's https server while still answering HTTPS - only inline PEM ran on the engine. sslForEngine() (present, never called) is now applied. The TLS integration test asserts getServerKind().server === 'engine' for both shapes, which it did not before.
The documented connection: socket => ... key of app.websocket() never ran: it was registered as a client-sendable event name. It now runs once per socket at open.
ws adapter: app.websocket('/name', ...) namespaces were unreachable, because the adapter created its server with an exact path: '/ws' that the ws library matches literally; /ws/name was rejected. The adapter now owns the upgrade step and routes any path below its base path (websocket.options.path, default /ws) to the matching namespace, or the default one; origin allowlist and maxPayload still apply through handleUpgrade, and an upgrade outside the base path is answered 404 instead of left hanging when no other listener claims it. Its disconnect: hook now fires with the close code.
Compression middleware: a Content-Length set for the uncompressed body is removed before a compressed body is committed (it would have truncated or hung the response).
Docs: the per-route .compression({ level }) route method shown in the middleware guide and on morojs.com never existed on RouteBuilder; the samples now use .before(middleware.compression({ ... })), which is tested.
Other
Engine stress test: 200 simultaneous connects from the test's own event loop overflow macOS's 128-entry listen backlog, which answers with RST on any server (the Node backend failed identically); the test keeps 64 requests in flight across the 200.
New suites: binary bodies and rawBody on Node and engine, raw WebSocket framing on engine and ws, TLS reload and ssl.watch on Node and engine, dual-stack listen, precompressed sidecars, container CPU/memory probes, the Redis adapter against a fake node-redis 4 client, and the configuration lock warning.
Docs: request-body rules and req.rawBody, raw WebSocket frames, app.reloadTLS() / ssl.watch, precompressed, container-aware workers: 'auto', Redis url; the morojs.com compression, static-files and websockets pages updated with the search index regenerated.