express-force-https is an Express.js middleware designed to automatically redirect all incoming HTTP requests to their HTTPS equivalent. First published over a decade ago, its current (and only) stable version is 1.0.0. The middleware specifically checks if a request is already secure; if not, it issues a redirect. A key feature is its built-in exemption for `localhost` requests, preventing redirects during local development. Due to its age and lack of updates, it is considered abandoned and may not be suitable for modern Express applications, especially those deployed behind reverse proxies or load balancers which require specific `X-Forwarded-Proto` header handling. Alternative, more actively maintained solutions are generally recommended for production environments.
npm install express-force-httpsVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to integrate the express-force-https middleware into a basic Express application to enforce HTTPS redirects for all routes, excluding localhost.
Consider using alternative, actively maintained solutions for HTTPS redirection, or implement custom middleware to leverage Express's `req.secure` property or `X-Forwarded-Proto` header check for robust proxy support.
Set `app.set('trust proxy', 1)` in your Express application to correctly interpret proxy headers. For robust proxy detection, it is generally safer to check `req.headers['x-forwarded-proto']` manually.To ensure a 301 redirect, implement custom middleware or use an alternative package that allows specifying the status code, e.g., `res.redirect(301, 'https://' + req.headers.host + req.url);`
Ensure Express is correctly installed and initialized. Upgrade Express to a compatible version. Place `app.use(forceHttps)` early in your middleware chain.
Add `app.set('trust proxy', 1);` to your Express application. For more control, consider replacing `express-force-https` with custom middleware that checks `req.headers['x-forwarded-proto'] === 'http'`.The middleware intentionally skips `localhost`. For other local development hostnames, explicitly exclude them in your proxy configuration or by adding a conditional check around the middleware in your development environment, e.g., `if (process.env.NODE_ENV === 'production') { app.use(forceHttps); }`.No dependency data recorded yet.