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

fastify-https-always

v1.0.0

Published

A fastify plugin to redirect http requests to https.

Downloads

116

Readme

Fastify https-always Plugin

This fastify plugin recognizes http requests and either redirects to an https URL or disallows the request. Useful to ensure connections utilize secure HTTP connection URLs. The logic is very similar to the express-ssl plugin.

This plugin can examine the request headers to determine if a request has been forwarded from a TLS-terminating proxy, a common deployment model. It relies on fastify’s trustProxy setting to learn the protocol and host name of a request sent through a proxy, such as an API gateway or load balancer.

Install

npm install fastify-https-always

Usage

To use the plugin, simply register it with the fastify instance. Be sure to consider the trustProxy setting for fastify. If your app will be deployed behind a proxy such as Heroku or an API gateway, then set trustProxy to true.

const fastify = require('fastify')({
  trustProxy: true
})

fastify.register(require('fastify-https-always'))

Configuration

This plugin has several optional configurations that can be used to change the behavior of the plugin. The following table lists these options for your configuration.

| Option | Default | Notes | | ---------------- | ----------------------------------------------------- | ------------------------------------------------------------ | | enabled | true | Enables the plugin. Useful in build systems where the plugin’s enabled state is driven by an environment variable. | | productionOnly | true | Only enable this plugin in production environments. Checks Node’s NODE_ENV environment variable for the standard production value. | | redirect | true | http requests will be redirected to the appropriate https service. If this config is false, then a 403 Forbidden error is returned instead. | | httpsPort | undefined (spec uses 443 as the default https port) | Use this value to change the https port used in the redirect Location header. |

Typescript Support

Fastify-https-always is written in Typescript and includes type declarations for the options.

import Fastify from "fastify"
import httpsAlwaysPlugin, {HttpsAlwaysOptions} from "fastify-https-always"

const fastify = Fastify({trustProxy: true})
// leave out options whose default is suitable
const httpsAlwaysOpts: HttpsAlwaysOptions = { 
  productionOnly: false, 
  redirect: false,
  httpsPort: 8443
}

fastify.register(allowPlugin, httpsAlwaysOpts)