LunaticServer
LunaticServer is the main class of the framework.
Extends
Constructor
Signature:
constructor(httpServer?: http.Server)where
httpServer:http.Server— the underlying Node.js HTTP server
Creates new LunaticServer instance. You can specify underlying http.Server,
for example, to enable https or for integration with other frameworks, such as
Socket.io:
import { LunaticServer } from '@shelepuginivan/lunatic'import { createServer } from 'http'import { Server } from 'socket.io'
const app = new LunaticServer()const httpServer = createServer(app.callback)const io = new Server(httpServer)Properties
httpServer
Type: readonly http.Server
The underlying Node.js HTTP server.
Methods
callback
Signature:
callback(req: httpIncomingMessage, res: http.ServerResponse): voidwhere
req:http.IncomingMessage— the incoming HTTP requestres:http.ServerResponse— server response
Callback function that handles requests. This method can be passed in different
methods and constructors, e.g. in http.Server constructor:
import { LunaticServer } from '@shelepuginivan/lunatic'import { Server } from 'http'
const app = new LunaticServer()const httpServer = new Server(app.callback)disable
Signature:
disable(feature: ApplicationFeature): LunaticServerwhere
feature:ApplicationFeature— feature to be disabled.
Disables the specified app feature.
enable
Signature:
enable(feature: ApplicationFeature): LunaticServerwhere
feature:ApplicationFeature— feature to be enabled.
Enables the specified app feature.
toggle
Signature:
toggle(feature: ApplicationFeature): LunaticServerwhere
feature:ApplicationFeature— feature to be toggled.
Toggles the specified app feature.
listen
Signature:
listen(port?: number, hostname?: string, backlog?: number): Promise<void>where
port:number | undefined— port that the server will listen onhostname:string | undefined— IP address that the server will listen onbacklog:number | undefined— maximum length of the queue of pending connections
Starts underlying httpServer with the specified parameters.
await app.listen(8000)is an equivalent of
import { LunaticServer } from '@shelepuginivan/lunatic'import { createServer } from 'http'
const app = new LunaticServer()
const httpServer = createServer()httpServer.on('request', app.callback)httpServer.listen(8000)renderer
Signature:
renderer(renderFunction: RenderFunction): LunaticServerwhere
renderFunction:RenderFunction— function that renders HTML templates
Specifies RenderFunction that will be used in
Response.render() and
Response.renderFile() for rendering HTML
templates.