Coder Social home page Coder Social logo

hapi-require-https's Introduction

hapi-require-https tests

hapi plugin that adds http to https redirection

By default, any incoming request with 'http' in X-Forwarded-Proto will be redirected (301) to the same host and path with 'https' as the protocol. You can optionally disable proxy mode and redirect based on the actual request protocol.

Usage

Just register the plugin and go!

server.register({
  plugin: require('hapi-require-https'),
  options: {}
})

API

plugin.register(server, [options])

Registers the plugin to run onRequest in the request lifecycle.

options

Type: object
Default: {}

proxy

Type: boolean
Default: true

Indicates whether the server expects requests coming from a reverse proxy (a common Node web server setup) or directly from the Internet. Set this to false if you'd like to redirect based on the actual protocol instead of the X-Forwarded-Proto header.

License

MIT © Ben Drucker

hapi-require-https's People

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

Watchers

 avatar  avatar  avatar  avatar

hapi-require-https's Issues

Additional Features

@bendrucker Would you be open to me adding some pull requests to extend the functionality of this module. I'm thinking things like

  • options to enforce SSL (e.g. any http request would be dropped)
  • options to enforce SSL without the X-Forwarded-Proto header set (detect if the request is encrypted or not and redirect appropriately)
  • etc.

Completely understand if you want to keep this simple and specific so not worries if you want to keep it as is.

An in-range update of tape is breaking the build 🚨

The devDependency tape was updated from 4.13.0 to 4.13.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

tape is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 9 commits.

  • 2914a7b v4.13.2
  • c4119c2 [patch] Print name of test that didnt end (#498)
  • 98b2695 [Tests] sync new test cases from master
  • d686aa2 [eslint] enable quotes rule
  • 4526b39 [Tests] add tests for edge cases and numerics
  • 398503c [Deps] update resolve
  • e6b6f11 [Refactor] remove unused code
  • 333c636 v4.13.1
  • 8af61fd [Fix] match/doesNotMatch: when passing, ensure the proper default assert message shows up

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Errors with {proxy: false} and multiple connections

Hi, FYI this throws when proxy: false and there's more than one connection configured. Here's a minimal repro.

Looks like what you want is:

- : request.server.info.protocol === 'http'
+ : request.connection.info.protocol === 'http'

I opened an issue on hapi about documenting request.connection: hapijs/hapi#3328

Also, this seems only likely to work when using default ports. Otherwise it would be redirecting to https on the same port that http was requested on.

Usage question

@bendrucker this is how I'm trying to use the plugin https://github.com/mozilla/srihash.org/compare/xmr-redirect-www

When I console.log PLUGINS, I see this:

[
  {
    plugin: {
      name: 'vision',
      multiple: true,
      pkg: [Object],
      requirements: [Object],
      register: [Function: register]
    }
  },
  {
    plugin: {
      name: 'inert',
      pkg: [Object],
      once: true,
      requirements: [Object],
      register: [Function: register]
    }
  },
  { register: [Function: register], name: 'hapi-require-https' }
]

Admittedly I'm trying to test this locally, and when I made the initial patch, we were using Hapi 16. But I'd swear this worked in the past locally.

Maybe I'm doing something wrong?

Thanks in advance!

support for the scoped v18 of hapi

now that hapi moved to packages scoped under @hapi, the current peerDependencies definition doesn't support the new package. Would you mind publishing a version that would include support for @hapi/hapi?

update to hapi 9

When I upgrade to hapi 9, and reinstall all my dependencies I get the following error
npm ERR! peerinvalid The package hapi does not satisfy its siblings' peerDependencies requirements!
npm ERR! peerinvalid Peer [email protected] wants hapi@8

I am using
node v0.12.7
npm v2.11.3

Thanks

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 it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

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

Once you have installed and configured CI on this repository correctly, 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 App’s white list on Github. You'll find this list on your repo or organization’s settings page, under Installed GitHub Apps.

Require HTTP does not redirect

Hello,

I've installed this module, setted it up by using proxy: false (since I'm testing locally) but for some reason I'm never redirected.
How come?

The service starts and all, but whenever I try to go to http://localhost:9443/restricted I'm never redirected. I explicitly need to insert the https.

I'm running on Node v4.5 and trying to access the site on Chrome Version 52.0.2743.116 (64-bit)

Here's my code. Also, I don't envs settup so it's using 0.0.0.0:9443:

var HapiRequireHTTPS = require('hapi-require-https');
var ServiceRoutes = require("./routes/service");

var server = new Hapi.Server();
var PORT = process.env.PORT || 9443;
var HOST = process.env.SERVICE_HOST || '0.0.0.0';

server.connection({
    labels: 'https',
    port: PORT,
    host: HOST,
    tls: {
            key: Fs.readFileSync(__dirname + '/../certs/mycert.com.key'),
            cert: Fs.readFileSync(__dirname + '/../certs/mycert.com.crt')
        },
    routes: {
        cors: {
            origin: ['*'],
            headers: ["Accept", "Authorization", "Content-Type", "If-None-Match", "Accept-language"],
            exposedHeaders: ["Authorization"]
        }
    }
});

let plugins = [
    {
        register: HapiRequireHTTPS,
        options: { proxy: false }
    }
]

server.register(plugins, function (err) {
    if (err) {
        console.error(err);
        process.exit(1);
    }

    //Initialize Routes on the server
    server.route(ServiceRoutes);
})

Glue interface

I'm using glue and it doesn't seem to be responding.

{
plugin: 'hapi-require-https'
},

Does the plugin require h202 (the proxy component installed.)
Thanks

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.