HttpServer
Wraps Express with sensible defaults (JSON body parsing, CORS, static asset folders) and starts listening immediately unless `listen: false` is supplied. You get the underlying Express instance back via `app`.
- port: number (default 80)
- bind: string (default 0.0.0.0)
- publicPaths: string[] (default ["./public"])
- services: array of { serviceName, method, function }
- listen: boolean (default true); set false to build app without binding a port
- listenCallback: function invoked after listen
- encoding: "json" | "urlencoded" (default json)
- corsOptions: passed to cors
- enableHtmxRendering: boolean to render .htmx files
const { HttpServer, METHODS } = require('redweb')
const server = new HttpServer({
port: 4000,
bind: '0.0.0.0',
publicPaths: ['./static'],
services: [
{ serviceName: '/ping', method: METHODS.GET, function: (req, res) => res.json({ pong: true }) },
],
enableHtmxRendering: true,
})
// Express is still available:
server.app.get('/health', (req, res) => res.send('ok'))Merges defaults, wires body parsing, CORS, static serving, optional HTMX rendering, registers REST services, and starts listening unless listen is false.
Use the returned `app` to add middleware or routes exactly like a normal Express server.