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

@quoin/node-http-with-https

v2.0.2

Published

Simple nodejs server with HTTP that redirects to HTTPS

Downloads

12

Readme

@quoin/node-http-with-https

Build Status

This library offers a very simple code to force HTTP traffic to go in HTTPS.

Usage

const fs = require('fs');
const httpWithHttps = require('@quoin/node-http-with-https');

const behindProxy = false;
const httpPort = 8080;
const httpsPort = 8443;
const httpsOptions = {
  key: fs.readFileSync('/path/to/your/file.key'),
  cert: fs.readFileSync('/path/to/your/file.cert'),
  requestCert: false,
  rejectUnauthorized: false
};
const app = express(); // This is your expressJS app.

const { httpServer, httpsServer } = httpWithHttps(httpsPort, behindProxy, httpsOptions, app);

httpServer.listen(httpPort, () => console.log(`HTTP on ${httpPort}.`));

httpsServer.listen(httpsPort, () => console.log(`HTTPS on ${httpsPort}.`));

where:

  • httpsPort: port that will be used to run the application on HTTPS.
  • behindProxy: Indicates if the server runs behind a proxy. This will prevent httpsPort to be appended to the hostname.
  • httpsOptions: HTTPS options to be passed to https.createServer().
  • app: the expressJS app to run.

Example

See fully working example.

To run the example:

git clone [email protected]:Quoin/node-http-with-https.git
cd node-http-with-https
npm install
npm start

You can then access to:

http://localhost:8080/
http://localhost:8080/test/with/path

You should get an error trying any other path, like:

http://localhost:8080/other

Both should redirect you to the HTTPS path. You will probably have a security warning because the certificate is self-signed.

See example/README.md to see how the self-signed certificate files were generated.

LetsEncrypt

This server will have a minimum support for letsencrypt. It will allow the validation of the acme-challenge in HTTP before redirecting to HTTPS. In order to do that, it must define the environment variable:

ACME_CHALLENGE=/some/path/that/is/used/by/certbot