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

qzx-mock-rest-server

v1.1.4

Published

the test server which use in dev environment, i can recieve rest api and then auto transfer to the direct file

Downloads

2

Readme

qzx-mock-rest-server

这是一个简单的服务器,基于EXPRESS,主要是提供了便捷的服务器的建立,这里主要在开发前端代码的时候需要模拟请求的时候使用,并不能正式的作为服务其使用。

解决的问题

在开发的过程中经常需要各种各样的REST请求,在开发前端代码的时候,往往为了前后端分离需要自己写REST接口。但是,那样比较麻烦,这里就是为了简便,将REST对应到相应的文件,当请求过来后,会寻找对应的文件,并执行。

文件寻找的规则

/a/b/c

如上,如果有一个这样的请求,则请求的规则是:

  1. 查看有没有 a-b-c.js,如果有,加载、执行
  2. 如果没有 向下递推,a-b.js 同时将c以参数的形式传递给处理函数,也就是说,假如a-b.js存在,那么,将会加载a-b.js

a-b.js的形式

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

};

这里的参数和expres的参数几乎一致,但是,这里多了一个data,就是上面的c,最终的参数是: ['c']

安装

npm install qzx-mock-rest-server --save-dev

使用

const mockServer = require("qzx-mock-rest-server");
let server = new mockServer(port, host, staticDirectory, serverRoot);

参数默认值

  • port 端口号,默认是8080
  • host host,默认是localhost
  • staticDirectory 静态目录,默认是./static
  • serverRoot rest接口的监听目录,默认是./server

使用已有的express实例

有的时候,需要使用已存在的服务器,比如webpack-dev-server,他也是基于express,这时,可以直接使用其express实例去指定需要监听的rest接口的目录。

onst mockServer = require("qzx-mock-rest-server");
...
mockServer.handler(app,"./server","./static",[(req,res,next)=>{

}]);
// app 由上下文传递过来,./server指明了需要监听的目录