npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

goto-https

v1.0.2

Published

An `express` middleware that redirects requests to `https://`, if necessary.

Downloads

6

Readme

goto-https

An express middleware that redirects requests to https://, if necessary.

Installation

npm install --save goto-https

Basic Usage

import * as express from "express";
import {gotoHttps} from "goto-https";

declare const trustProxy : boolean;

app = express();
/*
    Set to `true` if you are behind Nginx or some other proxy.
*/
app.set("trust proxy", trustProxy);
app.use(gotoHttps({
    enabled : true,
    /*
        You should not leave this empty.
        If your website is `example.com`,
        then you should put `example.com` in this array.
    */
    hostDomainWhitelist : [],
}));

See the type GotoHttpsOptions in src/goto-https.ts for more options.

Features

  • Domain whitelisting
  • RedirectDelegate (See src/goto-https.ts) to control redirect behaviour

Tests

See the test/run-time/input folder.

npm run test-run-time

Implementation Details

  • req.headers["host"] and req.headers["x-forwarded-host"] may be used, depending on express' trust proxy fn.

  • The redirect URL is derived by "https://" + parsedHost.host + req.originalUrl.

  • If an invalid host is found, the middleware responds with status code 404.

  • The default redirect status code is 302.

  • A valid host is a string that is non-empty and not all whitespace.

hostDomainWhitelist

  • Whitelisting domain.com will also whitelist all domains that end with the string domain.com. e.g. subdomain1.domain.com, subdomain2.domain.com, etc.

  • To whitelist specific subdomains, add each subdomain to the array individually.

    const hostDomainWhitelist = [
        `subdomain1.domain.com`,
        `subdomain4.domain.com`,
    ];
    //subdomain2.domain.com and subdomain3.domain.com are not whitelisted.
    //domain.com is also not whitelisted.