HTTP · In depth

HttpsServer

TLS-enabled variant of `HttpServer`. Accepts `ssl.key` and `ssl.cert` file paths, wraps them in an https server, and bootstraps the same middleware pipeline.

Explain it like I’m five

The simple mental model

HttpsServer is HttpServer with a locked, encrypted front door. It reads your certificate and key, then serves the same Express application through TLS.

When it fits

When should I use it?

Use it when the Node process terminates TLS itself instead of sitting behind a reverse proxy or managed load balancer.

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 { HttpsServer, METHODS } = require('redweb')

new HttpsServer({
  port: 4443,
  ssl: { key: './certs/dev.key', cert: './certs/dev.crt' },
  services: [
    { serviceName: '/secure', method: METHODS.GET, function: (req, res) => res.json({ ok: true }) },
  ],
})
  1. 1

    The key and certificate files are loaded before the listener starts.

  2. 2

    The standard HTTP middleware and services are attached to the Express app.

  3. 3

    The resulting HTTPS server binds on the configured port and handles encrypted requests.

Configuration

Choices you can make

  • All `HttpServer` options
  • ssl.key: path to private key (required)
  • ssl.cert: path to certificate (required)
Surface area

Methods and members

constructor(options)

Loads the provided key/cert pair, builds the Express app with BaseHttpServer, then creates and starts the HTTPS listener unless listen is false.