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

netlify-plugin-redirect-with-auth

v1.0.1

Published

Add redirects with authorization header set in env variable

Downloads

4

Readme

Netlify Plugin: Redirect with Auth

This Netlify build plugin allows you to add redirects with authentication headers to your Netlify site.

Features

  • Adds redirects with custom authentication headers - header is set in an environment variable, separate from the code in your repo
  • Works for both build and development environments
  • Configurable through the netlify.toml file

Installation

  1. First, install the plugin as an npm dependency:
npm install netlify-plugin-redirect-with-auth
  1. Then, add the plugin to your netlify.toml file:
[[plugins]]
package = "netlify-plugin-redirect-with-auth"

  [plugins.inputs]
  redirects = [
    { from = "/submit", to = "https://api.example.com/submit" },
    { from = "/api/*", to = "https://api.example.com/:splat" }
 ]
  1. Set the NETLIFY_REDIRECT_AUTH_HEADER environment variable:

    For production:

    • Go to your Netlify site dashboard
    • Navigate to Site settings > Build & deploy > Environment
    • Add a new environment variable:
      • Key: NETLIFY_REDIRECT_AUTH_HEADER
      • Value: Your desired authorization header (e.g., Bearer your-token-here)

    For development:

    • Create a .env file in your project root (if it doesn't exist already)
    • Add the following line to the .env file:
      NETLIFY_REDIRECT_AUTH_HEADER=Bearer your-token-here
    • This environment variable will be used when you run netlify dev

Note: Make sure to add .env to your .gitignore file to avoid committing sensitive information to your repository.

Configuration

Environment Variables

Set the following environment variable in your Netlify site settings:

  • NETLIFY_REDIRECT_AUTH_HEADER: The authentication header to be added to the redirects.

Plugin Inputs

Configure the plugin in your netlify.toml file:

[[plugins]]
package = "netlify-plugin-redirect-with-auth"

  [plugins.inputs]
  redirects = [
    { from = "/submit", to = "https://api.example.com/submit" },
    { from = "/api/*", to = "https://api.example.com/:splat" }
  ]

Each redirect object in the redirects array must have both from and to properties.

How It Works

  1. The plugin runs during the onPreBuild and onPreDev events.
  2. It checks for the presence of the NETLIFY_REDIRECT_AUTH_HEADER environment variable.
  3. It validates the redirects input to ensure it's a non-empty array of valid redirect objects.
  4. For each redirect, it adds a new redirect rule to the Netlify configuration with:
    • The specified from and to URLs
    • A status code of 200
    • The force flag set to true
    • The authentication header from the environment variable

Notes

  • This plugin adds the authentication header to all specified redirects.
  • The redirects are set to force (always redirect, even if the requested file exists).
  • The status code is set to 200 for all redirects.

Troubleshooting

If you encounter issues:

  1. Ensure the NETLIFY_REDIRECT_AUTH_HEADER environment variable is set correctly.
  2. Check that your redirects input in netlify.toml is formatted correctly.
  3. Verify that each redirect object has both from and to properties.

For more help, please open an issue in the plugin's GitHub repository.