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

menreiki-plugin-proxy

v1.0.0-dev.1

Published

menreiki开发服务器http proxy支持

Downloads

1

Readme

menreiki的开发服务器代理能力支持,支持express类型的服务器

安装

npm install menreiki-plugin-proxy -D

使用配置

menreiki.config.js中,添加如下代码:

exports.plugins = [
  'menreiki-plugin-proxy'
];

配置项

暂无

配置文件

请在项目的根目录添加proxy.config.js,如果插件添加到了menreiki.config.js,但是没有proxy.config.js那么会报错

典型格式:


module.exports = function(mockLocal) {
  return [
    [
      '**/*.json', // include, glob rule
      (req, res) =>
        mockLocal(req, res, { mockPath: '/mock', delay: 20 }),
      '**/*hot-update.json', // exclude
    ],
  ];
};

说明: 插件会根据配置的数组,按顺序进行查找匹配,一旦匹配就使用对应的处理函数(middleware)

一个典型的配置

包含3个部分,分别对应数组的0,1,2元素:

  • 匹配规则(基于glob表达式,使用minimatch包),必选项。 满足这个规则才可能使用对应的处理逻辑
  • 处理逻辑,目前提供了2种: mockLocalmockRemote,分别是module.exports对应函数的第一个参数和第二个参数
  • 排除规则(基于glob表达式,使用minimatch包),非必选。 如果设置了这个规则,那么如果传入url满足了这个规则,这个配置也是不能被匹配的。

所以一个配置要被使用,需要满足: 匹配规则匹配上,排除规则不匹配或者没设置

mockLocal

mockLocal指的是从本地读取mock数据进行返回,默认的menreiki项目采用这种方式

其签名为

function (req,
  res,
  options = {
    mockPath: '/mock',
    delay: 100,
    cors: true,
    exact: false
  }
) {

  }

所以我们在proxy.config.js的同样目录下添加一个mock目录,里面的文件格式对应的就是请求的接口。

比如请求了/platform/getUser.json,那么我们可以在mock目录下,新增子目录platform,然后在下面添加getUser.json文件。代理会自动将结果返回。

如果我们想要动态地根据输入去响应请求,那么可以将文件变为getUser.js

这时候支持2种方式:

  • 模块导出一个对象
  • 模块导出一个函数

第一种方式下,我们可能不关注入参,只想动态随机产生结果。 第二种方式下,可能我们会关注输入的值,想要根据输入有不同的相应

举例来说:

module.exports = function(req, res, urlObject) {
  // urlObject是通过`url` npm包解析的包含query的对象
}

mockRemote

mockRemote指的是将请求代理到远程服务器上去

一个典型的使用方式:


module.exports = function(_, mockRemote) {
  return [
    [
      '**/*.json', // include, glob rule
      (req, res) =>
        mockRemote(req, res, { target: 'http://target.net' }),
      '**/*hot-update.json', // exclude
    ],
  ];
};

更多选项,请参考http-proxy使用文档