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

express-devtool

v1.1.3

Published

本地开发API处理中间件,提供数据模拟,接口proxy,页面跳转等功能提升前端本地开发能力。

Downloads

19

Readme

express-devtool

本地开发API处理中间件,提供数据模拟,接口proxy,页面跳转等功能提升前端本地开发能力。

无论你基于是 webpack 还是 fis,都可以用 express-devtool 来进行API模拟转发。

加载中间件

app.use(require('express-devtool')({
    mockDir: path.join(__dirname, 'mock') //定义mock目录
}));

目录规范

mock
  ├─ server.conf // 配置中心
  ├─ sample.json // json数据
  ├─ dynamic.js // js动态数据
  ...

如何使用

前端接口的mock主要在server.conf里面进行配置

server.conf 配置语法

指令名称 正则规则 目标文件
  • 指令名称 支持 rewrite 、 redirect 和 proxy。
  • 正则规则 用来命中需要作假的请求路径
  • 目标文件 设置转发的目标地址,需要配置一个可请求的 url 地址。

1. mock 静态假数据

rewrite ^/api/user$ /mock/sample.json

{
    "error": 0,
    "message": "ok",
    "data": {
        "username": "younth",
        "age": 25,
        "company": "taobao"
    }
}

2. mock 动态假数据

node 服务器可以通过 js 的方式提供动态假数据。动态数据本质是一个 route. rewrite ^/api/dynamic/time$ /mock/dynamic.js

module.exports = function(req, res, next) {

  res.write('Hello world ');
  // set custom header.
  // res.setHeader('xxxx', 'xxx');
  res.end('The time is ' + Date.now());
};

// 更复杂的,可以直接引用其他模块,发送请求
var http = require('http');
var url = require('url');
var util = require('util');
var querystring = require('querystring');
// 通过nodejs来抓取线上的结果。这样就完成了动态获取线上数据的功能

module.exports = function(request, response, next) {

    var method = request.method;
    ...
};

3. proxy 到其他服务

proxy能力支持正则分组。支持post及get请求的proxy

proxy ^\/wmall\/privilege\/(.*)$  http://10.19.161.92:8059/wmall/privilege/$1

4. 重定向 redirect

redirect ^\/api\/taobao$ http://www.taobao.com