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

mihawk

v0.0.2

Published

A simple async api mock server tool, no render template

Downloads

4

Readme

simple tiny mockServer(just data-mock)

  • 只mock-data,而不mock页面,即返回的response中body多为json,而不会包含html代码,当然,理论上返回任何东西都可以,包括下载文件。需要手动在对应请求的处理js中写逻辑
  • 支持通过js动态二次修改返还的json数据,当js不存在是,不修改json,直接返还源数据
  • 支持在js中查询与请求相关的一些数据,比如querystring,request.body
  • js中可以控制改变statusCode,headers等
  • 支持跨域使用
  • mock数据采用json5解析,所以json中支持注释

使用

$ npm i -g mihawk
$ mihawk 8888

需要新建一个data文件夹

/data
   │
   ├── delete
   │     │
   │     ├──/*.js    DELETE 请求所对应的数据处理逻辑
   │     │
   │     └──/*.json  DELETE 请求所对应的数据
   │
   ├── get
   │     │
   │     ├──/*.js    GET 请求所对应的数据处理逻辑
   │     │
   │     └──/*.json  GET 请求所对应的数据
   │
   ├── post
   │     │
   │     ├──/*.js    POST 请求所对应的数据处理逻辑
   │     │
   │     └──/*.json  POST 请求所对应的数据
   │
   ├── put
   │     │
   │     ├──/*.js    PUT 请求所对应的数据处理逻辑
   │     │
   │     └──/*.json  PUt请求所对应的数据
   │
   ├── comApiData.js     (可选)异步接口公共数据处理函数,会对同名的json文件进行数据处理并返还
   │
   └── comApiData.json   (可选)异步接口公共数据

举个对应关系的栗子:

请求    : GET http://local:8888/a/b/c/d
独立JSON: data/get/a/b/c/d.json
DATA    :  独立JSON数据(有js就二次处理) + 公共JSON数据(有js就二次处理)

栗子

开启

$ mihawk 8888

访问  http://localhost:8888/index

mockData注意事项

如何自定义数据

以/get/index为例,index.js是对index.json二次处理,如果没有js则直接不处理,并返还json

/**
 * ctx是koa的app上下文,可以使用它操作很多东西
 * originData 是同名json的数据,这里是index.json
 */
function getMockData(ctx,originData){

    let query = ctx.query || {};//url queryString
    let reqBody = ctx.request.body || {};// post or form or other data

    // 可以直接使用JSON5进行解析最新的json标准!
    console.log("QueryString为:\r\n",JSON5.stringify(query,null,2));
    console.log("request-body为:\r\n",JSON5.stringify(reqBody,null,2));

    return {
        // statusCode: 200,
        // headers:{},
        body: originData
    };
}

// exports
module.exports = getMockData;