@valbo/redirect-to-https-middleware

Express middleware that redirects HTTP to HTTPS.

Usage no npm install needed!

<script type="module">
  import valboRedirectToHttpsMiddleware from 'https://cdn.skypack.dev/@valbo/redirect-to-https-middleware';
</script>

README

@valbo/redirect-to-https-middleware

Express middleware that redirects HTTP to HTTPS.

npm (scoped) semantic-release Build Status Coverage Status Known Vulnerabilities

Install

npm install @valbo/redirect-to-https-middleware

Usage

Add this middleware to your express app. To make it work behind a reverse proxy set trust proxy to true:

import { redirectToHttpsMiddleware } from '@valbo/redirect-to-https-middleware';

app.set('trust proxy', true);
app.use(redirectToHttpsMiddleware);

The middleware will redirect any request with the HTTP protocol to the same URL but with the HTTPS protocol, except if the server is localhost or 127.0.0.1.