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

ndps

v2.1.1

Published

A dynamic proxy server of nodeJS

Downloads

27

Readme

NDPS(node-dynamic-proxy-server)

Brief intro

在一个比较大的Angular项目中,开发和测试的环境往往都会有很多。所以在Angular前端的开发过程中,有时需要经常性的切换后端环境。

在angular-cli工程和webpack工程中都提供了修改的方法:

  • 在angular-cli工程中使用指令ng server -pc proxy.conf.json(.js)就能传入一个环境代理配置
  • 在webpack工程中则可以在webpack.config.js中通过配置devServer的proxy来实现。

但是,不论是angular-cli工程还是webpack工程,在开发模式下每次更换代理往往都需要重新start工程来使代理生效,而重新start就意味着一个webpack compile的过程,这对一个大型Angular工程来说时间开消是很大的,严重影响开发效率。 有没有一种办法,能让Angular工程在更改完http代理后不需要重新start就能自动生效呢? 这时候NDPS(node-dynamic-proxy-serve)就能派上用场了!

NDPS(Node-Dynamic-Proxy-Server)是一个基于nodeJS的动态代理服务器,如果在npm start前启用了NDPS,Angular-cli内置的dev-server的目标代理(proxyTarget)就会被设定到NDPS(http://localhost:8181), 此时,NDPS则会读取和监听上面的环境配置,并根据配置的把http请求转发到对应的后端服务器上。 这样做的主要好处是方便Start后需要更换后端环境的场景,NDPS可以在start的状态下动态切换环境,避免了重新运行npm start的时间消耗。

Quick start

Make sure you have Node version >= 6.0 and NPM >= 3

Install

$ npm install --save-dev ndps

Config

//package.json

{
  ...
  "scripts": {
    "server": ng serve -pc proxy.conf.js
    "mock": "node ./src/mock/mock.js",
    "ndps": "node proxy.conf.js ndps",
    "proxy": "node proxy.conf.js",
    ...
  }
  ...
}

// proxy.conf.js

const ndpsServer = require('ndps');

var proxies = /*proxies*/{
  0: 'http://localhost:8101',
  1: 'http://10.93.128.155:10080',
  2: 'http://10.62.107.136:10080',
}/*proxies*/;

var proxyTarget = proxies[ 0 ];

ndpsConf = {
  ndpsPort: 8181,
  proxiesAnchor: '/*proxies*/',
  proxyIdxAnchor: 'proxies[',
  proxyConfPath: __filename,
  beforeProxyChange: (info, done) => {
    //if (info.proxyIdx === 0 && !isMockStarted) {
    //  mockServer(!info.isInit, () => done());
    //  isMockStarted = true;
    //} else {
    //  done();
    //}
    done();
  }
};

var proxyConf = [{
  context: ["/api"],
  target: `http://localhost:${ndpsConf.ndpsPort}`,
  secure: false
}];

// Start NDPS
ndpsServer(ndpsConf);
 
// Export Conf
module.exports = proxyConf;

Effect pictures

Start NDPS: Change proxy target: Some other case:

License

MIT