GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - JustinBeckwith/yes-https: Say yes to https with express and connect.

BranchesTags
Open more actions menu

Latest commit

 

History

133 Commits
133 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
docs/assets
docs/assets
 
 
example
example
 
 
lib
lib
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.release-please-manifest.json
.release-please-manifest.json
 
 
AGENTS.md
AGENTS.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE.md
LICENSE.md
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
biome.json
biome.json
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
release-please-config.json
release-please-config.json
 
 
renovate.json
renovate.json
 
 

Repository files navigation

YES HTTPS!

Build Status codecov npm version Checked with Biome Release Please

An armored bear holding a shield in a forest

yes-https is a happy little npm module that makes it easy to require https for your connect based application.

It does this two ways:

  • Setting the Strict-Transport-Security HTTP header. Learn more at OWASP.
  • Automatically sending an HTTP 301 for the first request. This is often overlooked, as HSTS only works after the browser hits the https endpoint the first time.

Installation

npm install yes-https

Usage

import yes from 'yes-https';
import express from 'express';

let app = express();

// Use the yes-https connect middleware.  Note - this will only work if NODE_ENV is set to production.
app.use(yes());

app.get('/', (req, res) => {
  res.end('Thanks for checking it out!');
});

const server = app.listen(process.env.PORT || 3000, () => {
  console.log('App listening on port %s', server.address().port);
  console.log('Press Ctrl+C to quit.');
});

You can also set a few settings with the middleware to control the header:

app.use(yes({
  maxAge: 86400,            // defaults `86400`
  includeSubDomains: true,  // defaults `true`
  preload: true             // defaults `true`
}));

includeSubDomains is the canonical option name. For backwards compatibility, includeSubdomains is also accepted, and both spellings default to true.

Ignoring specific requests

In some cases, you may want to ignore a request and not force the redirect. You can use the ignoreFilter option to opt out of redirects on a case by case basis. This is useful if you want to ignore a specific route:

app.use(yes({
  ignoreFilter: (req) => {
    return (req.url.indexOf('/_ah/health') > -1);
  }
}));

Contributing

Pull requests welcomed!

About

Say yes to https with express and connect.

Topics

expresshttpsnodejs

Resources

Readme
MIT license

Security policy

Security policy
Activity

Stars

30 stars

Watchers

2 watching

Forks

2 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.