Documentation
Docs
Introduction
Getting Started
Tutorial: build an app
Core Concepts
Routing
Server-Side Rendering
Mimir, state management
Pages & Layouts
API Routes
Styling & Theming
Building & Deploying
API Reference
Guides
Recipes
FAQ (use cases)
httpsRedirect()
Send any plaintext request to its HTTPS URL with a 301, working behind a TLS-terminating proxy.
Use case
A site served over plain HTTP exposes cookies and content to anyone on the network. Redirecting every HTTP
request to HTTPS makes the secure URL the only one that works, and combined with HSTS (from helmet), repeat
visitors skip HTTP entirely.
How it works
It checks whether the request is already secure, using req.protocol and the X-Forwarded-Proto header set
by a TLS-terminating proxy (nginx, a load balancer). If it is HTTP, it replies 301 Moved Permanently to the
https:// URL of the same host and path; if already HTTPS, it calls next().
Configuration
| Option | Default | Notes |
|---|---|---|
httpsPort | 443 | Port in the redirect URL (omitted when 443). |
Example
Notes
Behind nginx (the recommended setup), you usually let nginx do the
80 -> 443redirect (certbot's--redirectadds it). Use this middleware when the rune app terminates TLS itself, or as belt-and-braces. It relies onX-Forwarded-Proto, which your proxy must set, or every request looks like plain HTTP.
Next: secureCookies.