All Projects → unjs → Redirect Ssl

unjs / Redirect Ssl

Licence: mit
Connect/Express middleware to enforce https using is-https

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Redirect Ssl

Pwa Wp
WordPress feature plugin to bring Progressive Web Apps (PWA) to Core
Stars: ✭ 445 (+449.38%)
Mutual labels:  https, pwa
Apicache
Simple API-caching middleware for Express/Node.
Stars: ✭ 957 (+1081.48%)
Mutual labels:  middleware, express
Kona
a node.js service framework built on koa.js (generators)
Stars: ✭ 23 (-71.6%)
Mutual labels:  middleware, express
Echo
High performance, minimalist Go web framework
Stars: ✭ 21,297 (+26192.59%)
Mutual labels:  middleware, https
Http Proxy Middleware
⚡ The one-liner node.js http-proxy middleware for connect, express and browser-sync
Stars: ✭ 8,730 (+10677.78%)
Mutual labels:  middleware, express
Express Openapi Validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification
Stars: ✭ 436 (+438.27%)
Mutual labels:  middleware, express
Go Bootstrap
Easy way to bootstrap a web server in Go (Routing|Middleware|Https)
Stars: ✭ 27 (-66.67%)
Mutual labels:  middleware, https
Twreporter React
twreporter site with nodejs
Stars: ✭ 263 (+224.69%)
Mutual labels:  express, pwa
Rainbow
An Express router middleware for RESTful API base on file path.
Stars: ✭ 53 (-34.57%)
Mutual labels:  middleware, express
Webpack Isomorphic Dev Middleware
The webpack-dev-middleware, but for isomorphic applications
Stars: ✭ 38 (-53.09%)
Mutual labels:  middleware, express
Express Promise
❤️ Middleware for easy rendering of async Query results.
Stars: ✭ 320 (+295.06%)
Mutual labels:  middleware, express
Express Joi Validation
validate express application inputs and parameters using joi
Stars: ✭ 70 (-13.58%)
Mutual labels:  middleware, express
Grant
OAuth Proxy
Stars: ✭ 3,509 (+4232.1%)
Mutual labels:  middleware, express
Express Jwt Permissions
🚦 Express middleware for JWT permissions
Stars: ✭ 444 (+448.15%)
Mutual labels:  middleware, express
Express Status Monitor
🚀 Realtime Monitoring solution for Node.js/Express.js apps, inspired by status.github.com, sponsored by https://dynobase.dev
Stars: ✭ 3,302 (+3976.54%)
Mutual labels:  middleware, express
Outputcache
Cache api responses using Redis, Memcached or any cache provider for NodeJS
Stars: ✭ 9 (-88.89%)
Mutual labels:  middleware, express
Express Basic Auth
Plug & play basic auth middleware for express
Stars: ✭ 241 (+197.53%)
Mutual labels:  middleware, express
Home
Project Glimpse: Node Edition - Spend less time debugging and more time developing.
Stars: ✭ 260 (+220.99%)
Mutual labels:  middleware, express
Hellobooks
A Single-Page Library Management App built with nodejs, express and react and redux
Stars: ✭ 37 (-54.32%)
Mutual labels:  express, pwa
The forge
Our groundbreaking, lightning fast PWA CLI tool
Stars: ✭ 70 (-13.58%)
Mutual labels:  express, pwa

redirect-ssl

Connect/Express middleware to enforce https using is-https.

version downloads ci

Usage

Install package:

yarn add redirect-ssl
# or
npm install redirect-ssl

Require and use redirect-ssl. Make sure to use this middlware as the first in your middleware chain (if using express see middleware chain:

import redirectSSL from 'redirect-ssl'
// or
const redirectSSL = require('redirect-ssl')

// Add middleware
app.use(redirectSSL)

// Using custom options
app.use(redirectSSL.create({ redirectPort: 8443 }))

Disable for non-production or localhost

If you want to disable on localhost, use the exclude option:

app.use(redirectSSL.create({
   exclude: ['localhost']
}))

Only enable in production environments:

app.use(redirectSSL.create({
  enabled: process.env.NODE_ENV === 'production'
}))

Options

trustProxy

  • Default: true

Trust and check x-forwarded-proto header for HTTPS detection.

enabled

  • Default: true

redirectPort

  • Default: 443

Redirect users to this port for HTTPS. (:443 is omitted from URL as is default for https:// schema)

redirectHost

  • Default: req.headers.host

Redirects using this value as host, if omitted will use request host for redirects.

NOTE It should not contain schema or trailing slashes. (Example: google.com)

redirectUnknown

  • Default: true

Redirect when no SSL detection method is available too. disable this option if you encounter redirect loops.

statusCode

  • Default: 307 Temporary Redirect

Status code when redirecting. The reason of choosing 307 for default is:

  • It prevents changing method from POST TO GET by user agents. (If you don't care, use 302 Found)
  • Is temporary so if for any reason HTTPS disables on server clients won't hurt. (If you need permanent, use 308 Permanent Redirect or 301 Moved Permanently)
  • See This question, 307 on MDN, and RFC 7231 section 6.4.7 for more info.

exclude

  • Default: []

An array of routes patterns for which redirection should be disabled.

Using with Nuxt.js

Add the redirect-ssl to the serverMiddleware array within in the nuxt.config.js file is the preferred usage:

import redirectSSL from 'redirect-ssl'

export default {
  serverMiddleware: [
    redirectSSL.create({
      enabled: process.env.NODE_ENV === 'production'
     }),
  ]
}

You will still need to install this package within your project for it work.

License

MIT. Made with 💖

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].