@morojs/moro / MoroEngineServer
Class: MoroEngineServer
Defined in: src/core/http/moro-engine-server.ts:1526
Moro Engine HTTP Server Adapter Bridges @morojs/engine with Moro's HTTP abstractions. Duck-typed to the same surface framework.ts/moro.ts use on UWebSocketsHttpServer.
Constructors
Constructor
new MoroEngineServer(
options?):MoroEngineServer
Defined in: src/core/http/moro-engine-server.ts:1698
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).
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:1666
Internal
read by EngineResponse for buffered-response compression
_end
_end: (
reqId,data?) =>void
Defined in: src/core/http/moro-engine-server.ts:1542
Internal
Parameters
reqId
number
data?
any
Returns
void
_endWith?
optional_endWith?: (reqId,chunk) =>void
Defined in: src/core/http/moro-engine-server.ts:1560
Internal
Parameters
reqId
number
chunk
any
Returns
void
_engine
_engine:
any
Defined in: src/core/http/moro-engine-server.ts:1528
Internal
read by EngineRequest/EngineResponse for lazy fetchers
_getBody
_getBody: (
reqId) =>ArrayBuffer|null
Defined in: src/core/http/moro-engine-server.ts:1547
Internal
Parameters
reqId
number
Returns
ArrayBuffer | null
_getHeader
_getHeader: (
reqId,name) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1546
Internal
Parameters
reqId
number
name
string
Returns
string | undefined
_getHeaders
_getHeaders: (
reqId) =>string[] |undefined
Defined in: src/core/http/moro-engine-server.ts:1545
Internal
Parameters
reqId
number
Returns
string[] | undefined
_getMethod
_getMethod: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1549
Internal
Parameters
reqId
number
Returns
string | undefined
_getQuery
_getQuery: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1544
Internal
Parameters
reqId
number
Returns
string | undefined
_getRemoteAddress
_getRemoteAddress: (
reqId) =>string|undefined
Defined in: src/core/http/moro-engine-server.ts:1548
Internal
Parameters
reqId
number
Returns
string | undefined
_isAborted
_isAborted: (
reqId) =>boolean
Defined in: src/core/http/moro-engine-server.ts:1543
Internal
Parameters
reqId
number
Returns
boolean
_prepareResponse?
optional_prepareResponse?: (serverId,status,headers) =>number
Defined in: src/core/http/moro-engine-server.ts:1553
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:1534
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:1558
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:1559
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:1587
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:1567
Internal
Parameters
serverId
number
method
number
path
string
status
number
headersFlat
string[] | null
body
any
Returns
void
_write
_write: (
reqId,chunk) =>boolean
Defined in: src/core/http/moro-engine-server.ts:1541
Internal
Parameters
reqId
number
chunk
any
Returns
boolean
_writeHead
_writeHead: (
reqId,status,headers) =>void
Defined in: src/core/http/moro-engine-server.ts:1540
Internal
Parameters
reqId
number
status
number
headers
string[] | null
Returns
void
isSsl
isSsl:
boolean=false
Defined in: src/core/http/moro-engine-server.ts:1621
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:1932
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:1869
Whether this engine build answers static routes itself.
Returns
boolean
Methods
_complete()
_complete(
reqId):void
Defined in: src/core/http/moro-engine-server.ts:1834
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:1842
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:1969
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:1907
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:2864
Parameters
callback?
(error?) => void
Returns
void
configurePerformance()
configurePerformance(
config):void
Defined in: src/core/http/moro-engine-server.ts:2799
Parameters
config
any
Returns
void
delete()
delete(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2174
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
enableWebSocket()
enableWebSocket(
bridge):void
Defined in: src/core/http/moro-engine-server.ts:2104
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:2956
Returns
void
get()
get(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2165
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
getApp()
getApp():
any
Defined in: src/core/http/moro-engine-server.ts:2952
Returns
any
getServer()
getServer():
any
Defined in: src/core/http/moro-engine-server.ts:2947
Returns
any
head()
head(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2183
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
listen()
Call Signature
listen(
port,callback?):void
Defined in: src/core/http/moro-engine-server.ts:2810
Parameters
port
number
callback?
() => void
Returns
void
Call Signature
listen(
port,host,callback?):void
Defined in: src/core/http/moro-engine-server.ts:2811
Parameters
port
number
host
string
callback?
() => void
Returns
void
options()
options(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2180
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
patch()
patch(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2177
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
post()
post(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2168
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
put()
put(
path, ...handlers):void
Defined in: src/core/http/moro-engine-server.ts:2171
Parameters
path
string
handlers
...(HttpHandler | Middleware)[]
Returns
void
setErrorHandler()
setErrorHandler(
fn):void
Defined in: src/core/http/moro-engine-server.ts:2129
Parameters
fn
(err, req, res) => any
Returns
void
setHookManager()
setHookManager(
hookManager):void
Defined in: src/core/http/moro-engine-server.ts:2795
Parameters
hookManager
any
Returns
void
setNativeRouteProvider()
setNativeRouteProvider(
_provider,_onError?):void
Defined in: src/core/http/moro-engine-server.ts:2269
Parameters
_provider
() => any[]
_onError?
(...args) => any
Returns
void
setParamRoute()
setParamRoute(
method,prefix,suffix,status?,headers?):boolean
Defined in: src/core/http/moro-engine-server.ts:1945
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:2142
Parameters
decorations
Record<string, any>
Returns
void
setRequestTracking()
setRequestTracking(
enabled):void
Defined in: src/core/http/moro-engine-server.ts:2787
Parameters
enabled
boolean
Returns
void
setResponseDecorations()
setResponseDecorations(
decorations):void
Defined in: src/core/http/moro-engine-server.ts:2147
Parameters
decorations
Record<string, any>
Returns
void
setRouterHandler()
setRouterHandler(
fn):void
Defined in: src/core/http/moro-engine-server.ts:2124
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:1882
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:2933
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:2766
Parameters
middleware
Returns
void
wsClose()
wsClose(
wsId,code?,reason?):void
Defined in: src/core/http/moro-engine-server.ts:2118
Close a WebSocket (RFC 6455 close frame).
Parameters
wsId
number
code?
number
reason?
string
Returns
void
wsSend()
wsSend(
wsId,data,isBinary):boolean
Defined in: src/core/http/moro-engine-server.ts:2113
Send a frame on a WebSocket. Returns false on backpressure.
Parameters
wsId
number
data
string | ArrayBuffer | Buffer<ArrayBufferLike>
isBinary
boolean
Returns
boolean