Giter Site home page Giter Site logo

redirect-ssl's Introduction

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 💖

redirect-ssl's People

Contributors

luc122c avatar marciodojr avatar marie-maxime avatar matthieusieben avatar nozomuikuta avatar onlyurei avatar paulgv avatar pi0 avatar renovate[bot] avatar ricardogobbosouza avatar xiwcx avatar zzhjerry avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

redirect-ssl's Issues

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on all branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because we are using your CI build statuses to figure out when to notify you about breaking changes.

Since we did not receive a CI status on the greenkeeper/initial branch, we assume that you still need to configure it.

If you have already set up a CI for this repository, you might need to check your configuration. Make sure it will run on all new branches. If you don’t want it to run on every branch, you can whitelist branches starting with greenkeeper/.

We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

Once you have installed CI on this repository, you’ll need to re-trigger Greenkeeper’s initial Pull Request. To do this, please delete the greenkeeper/initial branch in this repository, and then remove and re-add this repository to the Greenkeeper integration’s white list on Github. You'll find this list on your repo or organiszation’s settings page, under Installed GitHub Apps.

This question is available on Nuxt.js community (#c1)

Connection refused on new non index routes (Nuxt.js / Heroku)

This is probably a terribly specific issue and if you don't have time I completely understand, but I have a Nuxt.js app running on Heroku and I'm trying to force HTTPS. I've used the config outlined in your README however when I enable the module, I get some unwanted results.

Without Module:

  • all routes work
  • http and https work
  • new tabs work

With Module:

  • forces https correctly-
  • all routes work when navigated from /
  • new tabs/windows throw ECONNREFUSED error except for /

Detailed error:
Error: connect ECONNREFUSED 127.0.0.1:443 at TCPConnectWrap.afterConnect [as oncomplete]

This is running on Heroku, below is the relevant bits of the nuxt config file:

import redirectSSL from 'redirect-ssl'

export default {
  target: 'server',
  components: true,
  buildModules: [
    '@nuxtjs/eslint-module'
  ],
  serverMiddleware: [
    redirectSSL.create({
      enabled: process.env.NODE_ENV === 'production'
     }),
  ],
  modules: [
    '@nuxtjs/axios',
    '@nuxtjs/proxy',
    '@nuxtjs/redirect-module'
  ],
  redirect: [
    { from: '^/digital/(.*)$', to: '/' }
  ],
}

Any help/ideas would be greatly appreciated

Support SPA mode

From what I understand this doesn't work without node/express.

is SPA mode support in plans?

This question is available on Nuxt.js community (#c2)

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/setup-node v1
  • actions/cache v3
npm
package.json
  • is-https ^4.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

Exclude localhost redirect

How can I avoid a redirect on my localhost in order to execute my e2e test in local without a ssl certificat ?

I'm trying some trick like:
redirectSSL.create({ exclude: ['localhost'] })

How to use options in nuxt.config.js

How do I use the options? I tried this in nuxt.config.js:

    serverMiddleware: [
        [
            "redirect-ssl",
            {
                redirect: process.env.SSL_REDIRECT_ENABLED === "true"
            }
        ]
    ],

But I get error ServerMiddleware should expose a handle: undefined.

www to non-www

Describe the feature

Can this library also handle redirection from www to non-www version or vise-versa?

Additional information

  • Would you be willing to help implement this feature?

Compatible with Nuxt 3

Describe the feature

Is it possible to make this work with Nuxt3? If so, this is a request for documentation, otherwise it might be worth noting in the readme that the Nuxt example is for Nuxt 2 only.

Additional information

  • Would you be willing to help implement this feature?

Nuxt gives "Cannot get /" after installing "redirect-ssl" it into AWS nuxt project

Dear all

I am not sure if this issue is related to this module or with my configuration.
I am building project where i want to forcefully redirect non SSL links to SSL links.

Nuxt gives "Cannot get /" after installing and using this "redirect-ssl" it into AWS nuxt project
https://prnt.sc/xqsc05

Notes :

  • SSL is configured with port 443 and nuxt project is working fine on https without this redirect-ssl module
  • I want to forcefully redirect all non SSL routes to SSL (HTTPS)

Any suggestion or help please ?
nuxt_ssl

Exclude not working

I am coming back to my website project, and have noticed the exclude: ['localhost'] doesnt work. While working locally it still redirects to https and prevents me from connecting to the local website.

Getting too many redirect issue

Hi, I am using "nuxt": "^2.15.8", installed the package successfully but it is redirecting too many times :(

Any suggestions?

redirect-ssl not working on generated content

Hi,
i need to do an ssl redirect on my site to obtain from http://mysite.com to https://mysite.com
All the contents are created with Nuxt and the final version is generated via:
npm run generate command

But when I try to upload the site to my server (with a simple Apache installation and a valid certificate) if I use http protocol it does not redirect to https protocol.

Could you please show me the exact passes to implement your plugin in this cases?

Kindly,
Roberto

This question is available on Nuxt community (#c3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.