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-toggle-plugin

v0.2.2

Published

webpack plugin to toggle proxy

Downloads

8

Readme

proxy-toggle-plugin

npm

基于webpack-dev-server,通过装饰webpack-dev-server实现不重启服务切换代理,理论上基于webpack-dev-server启动的服务都能够使用。

注意事项

目前经过测试,umi框架暂不支持此插件。(推测原因: umi的proxy不是基于webpack-dev-server的,而是基于umi的)

安装

// npm
npm i proxy-toggle-plugin -D

//yarn
yarn add proxy-toggle-plugin -D

使用

配置

通过webpack配置使用:

const ProxyTogglePlugin = require("proxy-toggle-plugin");
module.exports = {
  // ...
  plugins: [
    new ProxyTogglePlugin(),
  ],
  // ...
};

通过chainWebpack配置使用:

const ProxyTogglePlugin = require("proxy-toggle-plugin");
module.exports = {
  // ...
  chainWebpack: (config) => {
      config.plugin('proxy-toggle-plugin')
      .use(ProxyTogglePlugin)
  },
  // ...
};

注意:使用了这个插件之后,你不应该再去配置webpack.devServer.proxy。你应该按照上述实例的方式来写 proxy 配置,这是 proxy 的经典配置写法,其他写法不确保成功。

配置文件

// 将文件放置在根目录下
proxyToggle.config.js
// 案例
module.exports = {
    // puppeteer 登录相关
    user: {
        // 谷歌浏览器启动路径
        executablePath: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
        loginUrl: 'http://baas.uban360.net:21006/portal/#/login',
        user: 'xxx',
        password: '******'
    },
    proxy: {
        // 将你所有的proxy配置写进来
        list: {
            环境a: {
                '/(baas-)|(content-center)': {
                    target: 'http://baas.uban360.net:21006/',
                    changeOrigin: true,
                    needCookies: true
                },
                '/sfs': {
                    target: 'http://baas.uban360.net:21006',
                    changeOrigin: true,
                    secure: false
                },
                '/uti-': {
                    target: 'http://baas.uban360.net:21006',
                    changeOrigin: true,
                    secure: false,
                    needCookies: true
                }
            },
            环境b: {
                '/(baas-)|(content-center)': {
                    target: 'http://baas.uban360.net:2333/',
                    changeOrigin: true,
                    needCookies: true
                },
                '/sfs': {
                    target: 'http://baas.uban360.net:21006',
                    changeOrigin: true,
                    secure: false
                }
            }
        },
        // 默认的proxy配置的key
        defaultProxy: '环境a',
    }
}

切换代理

插件提供了默认的 select 组件,可以通过此来动态切换代理

注意事项

ProxySelect.umd.js,ProxySelect.css两个文件放置在public目录下

<script src="./ProxySelect.umd.js"></script>
<link rel="stylesheet" href="./ProxySelect.css">
<script>
    window.onload = function () {
        // x: 左偏移 y: 上偏移
        new ProxySelect({x: 10, y: 10})
    }
</script>

获取 proxy 列表

  • url: /proxy/list
  • method: GET
  • res: {list: string[]}

切换 proxy 代理

  • url: /proxy/change
  • params: {proxy: string}
  • method: GET

协议

MIT