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

proxy-hot-reload-middleware

v1.0.1

Published

Express middleware for hot-reloading proxy configurations

Downloads

79

Readme

proxy-hot-reload-middleware

简体中文

The proxy-hot-reload-middleware middleware allows for dynamic updates to proxy configurations by monitoring changes in the configuration file, achieving hot-reloading of proxy settings without restarting the server.

Usage

  • Proxy Configuration Example
// proxyConfig.js
module.exports = [ 
    {
        context: '/api',
        target: 'http://127.0.0.1:3000',
        changeOrigin: true,
    }
]

Method 1: Using with webpack-dev-server

You can integrate this middleware into webpack-dev-server to enable hot-reloading of proxy configuration when running a React or other frontend project. This eliminates the need to restart the project when proxy settings change.

  • webpackDevServer.config.js
const proxyHotReloadMiddleware = require('proxy-hot-reload-middleware');

module.exports = function (proxy, allowedHost){
    return {
        // before (used for webpack-dev-server v3)
        // for webpack-dev-server v4, use onBeforeSetupMiddleware
        before(app, server, compiler) {
            app.use(proxyHotReloadMiddleware(proxyConfigPath)); // Use proxy configuration file path
        },
    }
}

Method 2: Using with Express

You can also use proxy-hot-reload-middleware directly in an Express server. This allows the proxy settings to be hot-reloaded without restarting the server when changes are made to the proxy configuration.

  • Example usage in Express
const express = require('express');
const app = express();
const proxyHotReloadMiddleware = require('proxy-hot-reload-middleware');

app.use(proxyHotReloadMiddleware(proxyConfigPath));

app.listen(3000);

How It Works

In certain development environments, such as when using webpack-dev-server for React projects, modifying the proxy configuration often requires restarting the development server for the changes to take effect. With proxy-hot-reload-middleware, the proxy settings are automatically reloaded whenever the configuration file is updated, so there is no need to restart the project manually.

Installation

  1. Install the package:
npm install proxy-hot-reload-middleware
  1. Set up your proxy configuration file (e.g., proxyConfig.js).

  2. Use the middleware as shown in the examples above, either within a webpack-dev-server configuration or an Express server.

By using this middleware, you can streamline the proxy configuration process and improve your development experience by avoiding unnecessary server restarts when working with proxy-based requests.

Publishing

This package is published to the official npm registry. The .npmrc file in the project root ensures that npm publish will use the correct registry.