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

switch-proxy-target

v0.0.1-13

Published

> 简化前端开发多套接口环境切换步骤 > 通过环境变量控制代理地址切换

Downloads

3

Readme

切换代理目标工具

简化前端开发多套接口环境切换步骤
通过环境变量控制代理地址切换

环境配置

  1. 安装npm install switch-proxy-target -g

  2. 初始化配置工具

用户目录下配置

❯ switch-proxy-target init  
init setting /path/to/cwd/.sptrc.json  
  1. 配置工具参数,编辑/path/to/cwd/.sptrc.json:

$schema该属性配置可以给开发工具提供json配置提示

{
  "targets": [
      {
          "name":"代理目标地址1",
          "hostname":"target1.example.org"
      }
   ],
  "syncHosts": [
      "选择目标需要同步的hosts域名,如:example.org"
   ]
}
  1. 修改项目proxy.conf.js配置中target:
{
    // ...
    target: `https://${process.env.PROXY_TARGET||'192.168.1.1'}`
    //...
}
  1. 增加package.jsonscripts可选配置
{
    "scripts":{
        //...
        "start": "ng serve",
        "start:switch": "switch-proxy-target run \"npm start\""
        //...
    }
}

功能特色

一键选择代理环境执行命令

  • switch-proxy-target run "npm start"npm run start:switch(需要环境配置5)
❯ npm run start:switch

> [email protected] start:switch /project/example/
> switch-proxy-target run "npm start"

? Please select the proxy target: 3环境:example.org   
----------Start detecting target accessability and fetch ip------------

正在 Ping example.org [192.168.1.1] 具有 32 字节的数据:

来自 192.168.1.1 的回复: 字节=32 时间=72ms TTL=62

192.168.1.1 的 Ping 统计信息:
    数据包: 已发送 = 1,已接收 = 1,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 72ms,最长 = 72ms,平均 = 72ms

ok !
----------Start setting proxy target------------
Create an environment variable "PROXY_TARGET=192.168.1.1"!

> [email protected] start:switch /project/example/
> ng serve

...

一键选择环境更新hosts(需要管理员权限)

  • switch-proxy-target hosts
❯ switch-proxy-target hosts 

? Please select the proxy target: 3环境:example.org   
----------Start detecting target accessability and fetch ip------------

正在 Ping example.org [192.168.1.1] 具有 32 字节的数据:

来自 192.168.1.1 的回复: 字节=32 时间=72ms TTL=62

192.168.1.1 的 Ping 统计信息:
    数据包: 已发送 = 1,已接收 = 1,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 72ms,最长 = 72ms,平均 = 72ms

ok !

sync hosts file example.org ok!

一键选择代理环境执行命令并同步修改hosts文件(需要管理员权限

  • npm run start:switch -- --syncEtcHosts
❯ npm run start:switch -- --syncEtcHosts

> [email protected] start:switch /project/example/
> switch-proxy-target run "npm start" --syncEtcHosts

? Please select the proxy target: 3环境:example.org   
----------Start detecting target accessability and fetch ip------------

正在 Ping example.org [192.168.1.1] 具有 32 字节的数据:

来自 192.168.1.1 的回复: 字节=32 时间=72ms TTL=62

192.168.1.1 的 Ping 统计信息:
    数据包: 已发送 = 1,已接收 = 1,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 72ms,最长 = 72ms,平均 = 72ms

ok !
----------Start setting proxy target------------
Create an environment variable "PROXY_TARGET=192.168.1.1"!

> [email protected] start:switch /project/example/
> ng serve

...