Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
mock-server-cli
Advanced tools
定义数据结构,自动生成模拟数据,方便在开发阶段迅速集成数据
npm i -g mock-server-cli
$ mock-server --help # 显示帮助信息
Usage: mock-server [options] [ --db mockdata | mockdata.json ]
Options:
-h, --help output usage information
-v, --version output the version number
--port [number] Port to use [3000]
--db [string] use the json database
--address [domain | ip] Address to use [localhost]
$ mock-server # 启动服务
mock server listening http://localhost:3000
访问定义的域名(默认: localhost)与端口号(默认:3000),可进入管理面板。即可看见当前项目已定义的所有接口,点击接口可以编辑接口。
http://localhost:3000
定义模拟数据接口时,可选择请求方式 任意
GET
POST
PUT
DELETE
OPTIONS
。
接口url可填写具体url,也可以使用 :param
方式定义带参数的路由,如果使用参数路由,在数据定义中可以使用占位符 @param(:param)
获取参数
@param(id)
@param(userid)
mockjs在key使用 |
符号定义数据结构,在 value 使用 @
定义数据类型,如
{
"users|10-50": [{ // 生成 10-50 个元素的数组
"id|+1": 10, // 从 10 开始,依次加 1
"name": "@cname", // 随机生成一个中文名字
"email": "@email", // 随机生成一个邮箱地址
"home": "@url(http)" // 随机生成 http 协议的url
}]
}
因为 mockjs 可能无法满足数据类型的定义,特别引入了 faker.js 增加数据类型的定义,在 value 使用 {{}}
定义数据类型,如
{
"name": "{{name.lastName}} {{name.firstName}}",
"company": "{{company.companyName}}",
"avatar": "{{image.avatar}}"
}
两种语法可以混用,使得更灵活配置
{
"users|10-50": [{
"id|+1": 10,
"name": "@cname",
"email": "@email",
"home": "@url(http)",
"realName": "{{name.lastName}} {{name.firstName}}",
"company": "{{company.companyName}}",
"avatar": "{{image.avatar}}"
}]
}
里面可以写一个函数,在保存时会执行函数 取返回值保存
FAQs
The npm package mock-server-cli receives a total of 1 weekly downloads. As such, mock-server-cli popularity was classified as not popular.
We found that mock-server-cli demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.