Configurable Express middleware that forces HTTPS based on the X-Forwarded-Proto header, commonly used behind proxies like Heroku, AWS ELB, and Nginx. Version 1.0.3 is the latest stable release (last updated 2018, in maintenance mode). It uses a header-based check rather than direct protocol detection, making it suitable for load-balanced or containerized environments. Unlike similar middleware (e.g., express-sslify), it provides options to skip certain user agents and disable the check via an enabled flag.
npm install express-force-https-schemaNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Minimal Express app with HTTPS redirection middleware using X-Forwarded-Proto header, skipping health checks.
Manually append the original query string from req.url after redirection, or use middleware like express-sslify which handles this.
Consider migrating to express-sslify or a custom middleware if security updates are needed.
Ensure your reverse proxy (e.g., Nginx, AWS ELB) sets the header correctly. For local development, set a test header or disable the middleware.
Use import forceHttpsSchema from 'express-force-https-schema' or const forceHttpsSchema = require('express-force-https-schema').defaultVerify proxy configuration (e.g., set X-Forwarded-Proto to https) and ensure the middleware is only applied to non-HTTPS requests.