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

sm-server

v0.7.2

Published

a mock server with node express

Downloads

1

Readme

前端 Mock 数据服务平台

基于 express、swagger 的 Mock 数据服务平台, 为对接接口的过程提供便利

介绍 :jack_o_lantern:

根据 swagger 数据源, 利用 expreesd 动态创建生成 router(包括 route path、route method),使 mock 接口具有校验参数, 返回 mock 数据的特性

目前只支持swagger 2.0 规范配置 JSON 数据格式

大概原理:

利用 swagger 的 path 生成对应的接口对应、path 下的 parameters 用来校验接口请求的参数、path 下面的 responses 用来 mock 接口返回接口参数,如果传参有误的话,则会返回具体错误详情。

快速开始

mock.config.ts 中配置好 swaggerUrl 或者 localPath 即可

// npm
npm i -g typescript
npm install

// yarn
yarn global add typescript
yarn install

然后在你的项目目录下执行npm run start即可

mock.config.ts 配置项

port

值类型:number

描述:mock server 端口号

localPath

值类型:string

描述:本地 swagger 配置文件夹的绝对路径(会遍历该文件夹下的所有文件 swagger 配置文件)

selectedTag

值类型:string

描述:对应 swagger config 的 tags,空的话,则选择全部 tags 的 path, 配置的话经过筛选后,只启动该 tag 下面的接口

url

值类型:string

描述:数据源的获取路径,目前只支持 Swagger 2.0。如 "https://petstore.swagger.io/v2/swagger.json"

isLocalOpenRedis

值类型:boolean

描述: 是否开始 redis 存储 swagger 配置(一般用于调试阶段)

isOpenValidParams

值类型:boolean

描述: 是否开始 redis 存储 swagger 配置(一般用于调试阶段)

codeMap

值类型:object

描述:成功,错误等状态码 Code 映射 Map

子字段:

  • 字段名:"success" 类型:number 含义:请求正确 code
  • 字段名:"unlogin" 类型:number 含义:没有登录 code(token 过期)
  • 字段名:"parameterError" 类型:类型:number 含义:传参错误

如:

codeMap: {
  success: 20000, // 成功逻辑code
  unlogin: 40001, // 没有登录
  parameterError: 40003, //参数错误
},