@morojs/moro / MoroEngineServer
Class: MoroEngineServer
Defined in: src/core/http/moro-engine-server.ts:1605
Moro Engine HTTP Server Adapter Bridges @morojs/engine with Moro's HTTP abstractions. Duck-typed to the surface framework.ts/moro.ts use on every HTTP server.
Constructors
Constructor
new MoroEngineServer(
options?):MoroEngineServer
Defined in: src/core/http/moro-engine-server.ts:1799
Parameters
options?
capabilities?
EngineCapabilities
Engine feature flags (from loadNativeEngine) - gates the ssl/http2/ limit options so we never pass a key an older engine won't parse.
engineModule?
any
Preloaded native engine module (from loadNativeEngine) - avoids a second resolution and keeps load failures at the framework's synchronous preflight instead of surfacing at listen()
http2Settings?
Http2ServerOptions
HTTP/2 settings when serving ALPN h2 natively (engine caps.http2).
lendBodies?
boolean
server.lendBodies: unparsed (binary) bodies are views over the engine's bytes, valid until the response is sent.
limits?
HttpRuntimeLimits
Flattened runtime limits (bytes/ms) from the framework.
maxBodySize?
number
maxUploadSize?
number
reusePort?
boolean
Bind with SO_REUSEPORT so cluster workers can share the port (POSIX only; the framework gates Windows clustering to Node)
ssl?
Record<string, any> | null
Normalized SSL config projected for the engine (both shapes).
Returns
MoroEngineServer
Properties
_compression
_compression:
CompressionSettings
Defined in: src/core/http/moro-engine-server.ts:1766
Internal
read by EngineResponse for buffered-response compression
_end
_end: (
reqId,data?) =>void
Defined in: src/core/http/moro-engine-server.ts:1621
Internal
Parameters
reqId
number
data?
any
Returns
void
_endWith?
optional_endWith?: (reqId,chunk) =>void
Defined in: src/core/http/moro-engine-server.ts:1660
Internal
Parameters
reqId
number
chunk
any
Returns
void
_engine
_engine:
any
Defined in: src/core/http/moro-engine-server.ts:1607
Internal
read by EngineRequest/EngineResponse for lazy fetchers
_getBody
_getBody: (
reqId) =>ArrayBuffer|null
Defined in: src/core/http/moro-engine-server.ts:1626
Internal
Parameters
reqId
number
Returns
ArrayBuffer | null
_getHeader
_getHeader: (
reqId,name) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1625
Internal
Parameters
reqId
number
name
string
Returns
string | undefined
_getHeaders
_getHeaders: (
reqId) =>string[] |undefined
Defined in: src/core/http/moro-engine-server.ts:1624
Internal
Parameters
reqId
number
Returns
string[] | undefined
_getMethod
_getMethod: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1633
Internal
Parameters
reqId
number
Returns
string | undefined
_getQuery
_getQuery: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1623
Internal
Parameters
reqId
number
Returns
string | undefined
_getRemoteAddress
_getRemoteAddress: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1632
Internal
Parameters
reqId
number
Returns
string | undefined
_isAborted
_isAborted: (
reqId) =>boolean
Defined in: src/core/http/moro-engine-server.ts:1622
Internal
Parameters
reqId
number
Returns
boolean
_prepareResponse?
optional_prepareResponse?: (serverId,status,headers) =>number
Defined in: src/core/http/moro-engine-server.ts:1653
Internal
Parameters
serverId
number
status
number
headers
string[] | null
Returns
number
_respond
_respond: (
reqId,status,headers,body) =>void
Defined in: src/core/http/moro-engine-server.ts:1613
Internal
Parameters
reqId
number
status
number
headers
string[] | null
body
any
Returns
void
_respondPrepared?
optional_respondPrepared?: (reqId,tplId,body) =>void
Defined in: src/core/http/moro-engine-server.ts:1658
Internal
Parameters
reqId
number
tplId
number
body
any
Returns
void
_respondPreparedEmpty?
optional_respondPreparedEmpty?: (reqId,tplId) =>void
Defined in: src/core/http/moro-engine-server.ts:1659
Internal
Parameters
reqId
number
tplId
number
Returns
void
_setParamRoute?
optional_setParamRoute?: (serverId,method,prefix,suffix,status,headersFlat) =>void
Defined in: src/core/http/moro-engine-server.ts:1687
Internal
Parameters
serverId
number
method
number
prefix
string
suffix
string
status
number
headersFlat
string[] | null
Returns
void
_setStaticRoute?
optional_setStaticRoute?: (serverId,method,path,status,headersFlat,body) =>void
Defined in: src/core/http/moro-engine-server.ts:1667
Internal
Parameters
serverId
number
method
number
path
string
status
number
headersFlat
string[] | null
body
any
Returns
void
_upgradeToWebSocket
_upgradeToWebSocket: (
reqId) =>number
Defined in: src/core/http/moro-engine-server.ts:1638
Internal
Parameters
reqId
number
Returns
number
_write
_write: (
reqId,chunk) =>boolean
Defined in: src/core/http/moro-engine-server.ts:1620
Internal
Parameters
reqId
number
chunk
any
Returns
boolean
_writeHead
_writeHead: (
reqId,status,headers) =>void
Defined in: src/core/http/moro-engine-server.ts:1619
Internal
Parameters
reqId
number
status
number
headers
string[] | null
Returns
void
_wsClose
_wsClose: (
wsId,code?,reason?) =>void
Defined in: src/core/http/moro-engine-server.ts:1637
Internal
Parameters
wsId
number
code?
number
reason?
string
Returns
void
_wsSend
_wsSend: (
wsId,data,isBinary) =>boolean
Defined in: src/core/http/moro-engine-server.ts:1636
Internal
Parameters
wsId
number
data
any
isBinary
boolean
Returns
boolean
isSsl
isSsl:
boolean=false
Defined in: src/core/http/moro-engine-server.ts:1721
Internal
read by EngineRequest#protocol/socket.encrypted - true when the engine is terminating TLS for this server (engine >= 1.1.6 + ssl passed)
Accessors
paramRoutesEnabled
Get Signature
get paramRoutesEnabled():
boolean
Defined in: src/core/http/moro-engine-server.ts:2064
Whether this engine build answers parameter routes itself.
Returns
boolean
staticRoutesEnabled
Get Signature
get staticRoutesEnabled():
boolean
Defined in: src/core/http/moro-engine-server.ts:2001
Whether this engine build answers static routes itself.
Returns
boolean
Methods
_complete()
_complete(
reqId):void
Defined in: src/core/http/moro-engine-server.ts:1966
Internal
terminal write/abort cleanup - drops the reqId mapping
Parameters
reqId
number
Returns
void
_template()
_template(
kind,status):number
Defined in: src/core/http/moro-engine-server.ts:1974
Internal
Template id for one of the framework's fixed header sets (TPL_*) at a status, materialised in the engine on first use; -1 when the engine has no templates (callers then respond() with the same headers) or the engine's per-server store is full.
Parameters
kind
number
status
number
Returns
number
clearParamRoutes()
clearParamRoutes():
void
Defined in: src/core/http/moro-engine-server.ts:2101
Drop every engine-answered parameter route; the JS routes are untouched.
Returns
void
clearStaticRoutes()
clearStaticRoutes():
void
Defined in: src/core/http/moro-engine-server.ts:2039
Drop every engine-answered static route; the JS routes are untouched.
Returns
void
close()
close(
callback?):void
Defined in: src/core/http/moro-engine-server.ts:3149
Parameters
callback?
(error?) => void
Returns
void
configurePerformance()
configurePerformance(
config):void
Defined in: src/core/http/moro-engine-server.ts:3083
Parameters
config
any
Returns
void
delete()
delete(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2326
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
enableWebSocket()
enableWebSocket(
bridge):void
Defined in: src/core/http/moro-engine-server.ts:2236
Register the engine WebSocket bridge; upgrade requests then route natively.
Parameters
bridge
onClose
onMessage
onOpen
Returns
void
forceCleanup()
forceCleanup():
void
Defined in: src/core/http/moro-engine-server.ts:3241
Returns
void
get()
get(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2317
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
getApp()
getApp():
any
Defined in: src/core/http/moro-engine-server.ts:3237
Returns
any
getServer()
getServer():
any
Defined in: src/core/http/moro-engine-server.ts:3232
Returns
any
head()
head(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2335
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
listen()
Call Signature
listen(
port,callback?):void
Defined in: src/core/http/moro-engine-server.ts:3094
Parameters
port
number
callback?
() => void
Returns
void
Call Signature
listen(
port,host,callback?):void
Defined in: src/core/http/moro-engine-server.ts:3095
Parameters
port
number
host
string
callback?
() => void
Returns
void
options()
options(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2332
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
patch()
patch(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2329
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
post()
post(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2320
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
put()
put(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2323
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
setErrorHandler()
setErrorHandler(
fn):void
Defined in: src/core/http/moro-engine-server.ts:2281
Parameters
fn
(err, req, res) => any
Returns
void
setHookManager()
setHookManager(
hookManager):void
Defined in: src/core/http/moro-engine-server.ts:3079
Parameters
hookManager
any
Returns
void
setParamRoute()
setParamRoute(
method,prefix,suffix,status?,headers?):boolean
Defined in: src/core/http/moro-engine-server.ts:2077
Register a route with one variable path segment, between prefix and
suffix, that the engine answers itself with that segment as the body:
"/user/" + "" for /user/:id. The segment goes out undecoded, as it is
on the wire. Returns false when this engine cannot take it (no
capability, compression on, or an unindexed method), so the caller keeps
its JS handler. Registering the same (method, prefix, suffix) again
replaces the earlier reply.
Parameters
method
string
prefix
string
suffix
string
status?
number = 200
headers?
string[] | Record<string, string | number | string[]> | null
Returns
boolean
setRequestDecorations()
setRequestDecorations(
decorations):void
Defined in: src/core/http/moro-engine-server.ts:2294
Parameters
decorations
Record<string, any>
Returns
void
setRequestTracking()
setRequestTracking(
enabled):void
Defined in: src/core/http/moro-engine-server.ts:3072
Parameters
enabled
boolean
Returns
void
setResponseDecorations()
setResponseDecorations(
decorations):void
Defined in: src/core/http/moro-engine-server.ts:2299
Parameters
decorations
Record<string, any>
Returns
void
setRouterHandler()
setRouterHandler(
fn):void
Defined in: src/core/http/moro-engine-server.ts:2276
Parameters
fn
(req, res) => boolean | Promise<boolean>
Returns
void
setStaticRoute()
setStaticRoute(
method,path,status?,headers?,body?):boolean
Defined in: src/core/http/moro-engine-server.ts:2014
Register a fixed reply for one (method, path) that the engine serves without calling into JS: no routing, no middleware, no hooks and no header building per request. The bytes on the wire are those of respond(status, headers, body). Returns false when this engine cannot take it (no capability, or a method the engine does not index), so the caller keeps its JS handler as the answer. Registering the same (method, path) again replaces the earlier reply.
Parameters
method
string
path
string
status?
number = 200
headers?
string[] | Record<string, string | number | string[]> | null
body?
string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Buffer<ArrayBufferLike> | null
Returns
boolean
updateSsl()
updateSsl(
ssl):void
Defined in: src/core/http/moro-engine-server.ts:3218
Replace the TLS certificate/key for every handshake from now on (engine capabilities.tlsReload). Established connections keep the context they handshaked with. Validated by the engine before the swap: a bad config throws and the current certificate keeps serving.
Parameters
ssl
Record<string, any>
Returns
void
use()
use(
middleware):void
Defined in: src/core/http/moro-engine-server.ts:3051
Parameters
middleware
Returns
void
wsClose()
wsClose(
wsId,code?,reason?):void
Defined in: src/core/http/moro-engine-server.ts:2270
Close a WebSocket (RFC 6455 close frame).
Parameters
wsId
number
code?
number
reason?
string
Returns
void
wsHandshake()
wsHandshake(
wsId): {flat:string[] |undefined;ip:string;query:string; } |undefined
Defined in: src/core/http/moro-engine-server.ts:2257
The handshake of a WebSocket the engine upgraded itself: the peer's address, the request headers as the engine's flat list and the raw query string. undefined without the capability, or once the socket is gone (the engine keeps it for the socket's lifetime, through onWsClose).
Parameters
wsId
number
Returns
{ flat: string[] | undefined; ip: string; query: string; } | undefined
wsSend()
wsSend(
wsId,data,isBinary):boolean
Defined in: src/core/http/moro-engine-server.ts:2265
Send a frame on a WebSocket. Returns false on backpressure.
Parameters
wsId
number
data
string | ArrayBuffer | Buffer<ArrayBufferLike>
isBinary
boolean
Returns
boolean