HTTP · In depth

BaseHttpServer

Public Express app builder used by HttpServer and HttpsServer. Use it for advanced composition when you want Redweb middleware, static files, and services without any listener behavior.

Explain it like I’m five

The simple mental model

BaseHttpServer prepares the kitchen but does not open the restaurant. You get a fully arranged Express app and decide which Node server will serve it.

When it fits

When should I use it?

Use it for custom composition, tests, serverless adapters, or any setup where creating and listening on the HTTP server belongs to your application.

A practical API pattern

Follow the example

This pattern explains the named API. Application classes, credentials, and assets may need to be supplied; use a complete recipe for a runnable starting point.

Read this article as Markdown

JavaScript
const { BaseHttpServer, METHODS } = require('redweb')

const base = new BaseHttpServer({
  publicPaths: ['./public'],
  services: [
    { serviceName: '/health', method: METHODS.GET, function: (req, res) => res.json({ ok: true }) },
  ],
})

base.app.get('/extra', (req, res) => res.send('ok'))
  1. 1

    The constructor configures either your Express app or a new one.

  2. 2

    Static folders and service definitions are registered in deterministic order.

  3. 3

    You pass base.app to http.createServer, a test harness, or another host when you are ready.

Configuration

Choices you can make

  • All `HttpServer` app-building options
  • server: existing Express application to configure
  • listen is ignored because BaseHttpServer never binds a port
Surface area

Methods and members

constructor(options)

Builds or configures an Express app with body parsing, CORS, static serving, and REST services.

app (Express instance)

The configured Express application. Pass it to http.createServer(app) for custom server ownership.