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

free-mock

v1.0.6

Published

mock数据快速集成到项目当中

Downloads

3

Readme


title: mock配置文件使用说明 tags: mock free-mock

应用场景

1、后端接口未调通之前,拦截某一个接口,返回一些自己生成的随机数据 2、某个测试机器上有数据,本地调试可以直接拉取测试机上的数据

使用方法

1、请在配置文件module.export后面对象增加属性和值 2、属性代表你需要拦截的api 3、值也是一个对象,它包含三个属性 target、pathRewrite、mockData 4、填写相应的值就可以得到对应的模拟数据

参数说明

1、主属性值代表需要拦截的api,比如你要拦截'/api/list',请填写'/api/list' 2、target 填写您需要代理到的目标服务器,不填写默认是'http://localhost:3000' 3、pathRewrite可以重写你的请求到指定位置(如果填写,就会得到你填写后代理地址所得数据,如果不填写,会得到mockData生成的数据,可以写多个哦) 示例: '^/api' : '/new/api/', // rewrite path 4、mockData是在没有设置pathRewrite时生成的数据,可以直接写数据,也可以使用mockjs的方式生成随机数据 注:详情参考http://mockjs.com/examples.html

安装

   npm install free-mock

用法示例

    var app = express();
    var freeMock = require('free-mock');
    // 传入配置文件地址
    app.use(freeMock(path.join(__dirname, 'mock/conf')));
    app.use('/', index);
    app.use('/users', users);

配置文件示例

module.exports = {
    '/api': {
        target: 'http://localhost:3000',
        pathRewrite:{
            '^/api': '/api/123'
        },
        mockData: {
            // 属性 list 的值是一个数组,其中含有 1 到 10 个元素
            'list|1-10': [{
                // 属性 id 是一个自增数,起始值为 1,每次增 1
                'id|+1': 1
            }]
        }
    }
};