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

http-proxy-middleware-secure-cookies

v0.1.8

Published

Securely add cookies to your http-proxy requests

Downloads

255

Readme

http-proxy-middleware-secure-cookies

Securely make authenticated requests to a remote server inside Webpack Dev Server proxies.

This library helps you create an http-proxy-middleware that securly makes proxy requests with cookies. It will prompt you to enter auth cookies at initial start or when authentication failed.

Problem Statement

Imagine you have an API backend and a totally separate frontend. The dev environment for the backend is very complex to setup so sometimes you'd prefer to let local frontend dev server make direct requests to the production services or some shared environment.

Now the tricky thing is the production service may require authentication. You local proxy has to bear the authentication headers or cookies in order to make requests to the API service. This package allows you to more easily manage and securely store the credentials needed for making these requests.

Usage

In webpack.config.js, add devServer proxy rules like below:

const { secureCookiesProxy } = require('http-proxy-middleware-secure-cookies');

module.exports = {
  // ...
  devServer: {
    // ...
    proxy: {
      // use the default options to proxy /api/* to https://foo.example.com/api/*
      '/api/*': secureCookiesProxy('https://api.example.com'),

      // different endpoints share the same account
      '/proxy/fiz': secureCookiesProxy({
        target: 'https://bar.example.com',
        keychainAccount: 'example.com',
      });
      '/proxy/buz': secureCookiesProxy({
        target: 'https://buz.example.com',
        keychainAccount: 'example.com',
      });
  }
}

module.exports = config;

This will automatically proxy local requests for http://locahost:$PORT/proxy/* to https://proxy-target.example.com. If the server returns a 401 HTTP status code, the dev server will automatically prompt you to enter a cookie string, store it in file system or the system keychain (when available), then use the cookies to authenticate future requests.

Secure Cookie Storage

By default, the package will try to install node-keytar to store the cookies in system keychain, if for some reason the installation failed (e.g., libsecret not pre-installed on Linux), we will fallback to using local files. By default the local file used is ${process.cwd()}/.proxy-cookies/[keychainAccount]. You can change the storage directory with following code (not recommended):

const os = require('os');
const { setCookieDirectory } = require('http-proxy-middleware-secure-cookies/dist/storage');

// change it to home directory so cookies can be shared across apps
setCookieDirectory(`${os.homedir()}/.proxy-cookies`);

Options

Pass options via secureCookieProxy(options).

License

The MIT License.