Socket
Socket
Sign inDemoInstall

@iitrend/mock-server

Package Overview
Dependencies
80
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @iitrend/mock-server

IITrend Mock Server.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

mock-server

接口模拟数据-服务器

使用/启动方法

const MockServer = require('@iitrend/mock-server')
// 建议在业务代码编译完成之前启动
new MockServer({
    mockPort: 8810
})

核心 API

new MockServer(config)

启动一个 Server 监听接受请求,并交由 @iitrend/mock-server/core 处理并生成模拟数据。

参数
config
// 以下为默认参数
{
    // 自动启动服务
    autoStart: true,

    // server
    mockHost: 'localhost',
    mockPort: 8810,

    // 配置非json文件指向(匹配中的使用使用js加载方式)
    mockData: {
        'static/static-config': true
    },
    // 默认为项目根目录下的 => 'mock/src/’
    mockDataPath: path.join(process.cwd(), 'mock/src/'),

    // 接口请求延迟(取区间随机值)
    mockDelays: [0, 300],

    // express app headers
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Access-Control-Allow-Headers': '*',
        'Access-Control-Allow-Methods': '*',
        'Content-Type': 'application/json;charset=utf-8'
    }

    // Mock.Random.extend
    // mockExtends: {},

    // http://localhost:8810/WHActs/Api/index.php/Client/Home/showIndex => 'Client/Home/showIndex'
    // parseMockFile: (url = '') => url.replace(/\?\S*/ig, '').split('/').slice(-3).join('/')
}
目录结构
mock/src/**/*.json
# 例如请求接口:Client/Home/showIndex
文件及目录:mock/src/Client/Home/showIndex.json
{
    "user": "@first()",
    "nickname": "@cname()",
    "realname": "@cname()",
    "firm_name": "广州@ctitle(2,5)有限公司",
    "dept_name": "@ctitle(2,5)部",
    "sex|1-2": 1,
    "birthday": "@timestamp()",
    "intro": "@ctitle(5,10)",
    "area": "@province()",
    "target_step_list": [2000, 4000, 6000, 8000, 10000, 12000],
    "target_step_n|+1": [2000, 4000, 6000, 8000, 10000, 12000],
    "step_n|10000-20000": 10000,
    "step_today|10000-20000": 10000,
    "cal_n|10000-20000": 10000,
    "cal_today|1000-2000": 10000,
    "icon": "@imageFix(50x50)",
    "firm_icon": "@imageFix(200x100)",
    "phone": "@phone()",
    "addr": {
        "id|+1": 1,
        "name": "@cname()",
        "addr": "@province()@city()@county()@ctitle(1,3)街@integer(1,2000)号",
        "phone": "@phone()"
    },
    "weight|50000-100000": 70000,
    "height|100-240": 1
}

Keywords

FAQs

Last updated on 08 Apr 2024

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc