1.4.24 • Published 2 years ago

visualization-mock-server v1.4.24

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

visualization-mock-server

version

基于本地 mock 文件生成本地 mock 服务器

服务器基于express

mock 文件目录如下

└── mock
│   ├── empty.js
│   ├── login.js
│   └── products.js

接口文件格式如下

login.js

export default {
	"GET /function": (_req, res) => {
		res.json({
			success: true,
			data: {},
			errorCode: 0,
		});
	},
	"GET /object": {
		name: "zzz",
		age: 21,
	},
	"GET /string": "string",
	"GET /boolean": false,
	"GET /number": 1,
	"GET /array": [
		{
			name: "zzz",
			age: 21,
		},
		{
			name: "zzz2",
			age: 22,
		},
	],
};

支持 mock 数据类型

  • Object
  • Array
  • Function
    • 入参分别对照expressreqresnext
  • String
  • Number
  • Boolean
  • HTMLElement后续补上
  • 文件后续会补上

安装

npm i visualization-mock-server -D

使用

mockServer 使用

const initMockServer = require("visualization-mock-server");

initMockServer({ port: 4001, host: "localhost" });

devServerMiddleware 使用

const { devServerMiddleware } = require("visualization-mock-server");

const { onBeforeSetupMiddleware, before } = devServerMiddleware();

// webpack.config.js

module.exports = {
	devServer: {
		onBeforeSetupMiddleware: devServerMiddleware().onBeforeSetupMiddleware,
	},
	// 更早的devServer版本需要用before
	devServer: {
		before: devServerMiddleware().before,
	},
};

针对不同的webpack-dev-server版本,考虑使用onBeforeSetupMiddlewarebefore

具体可查看devServer 暴露的 api 情况

TODO

  • 可借助express插件丰富 mock server 的用法
    • express-art-template art-template body-parser 等
  • cicd
  • 自动化构建流程
1.4.24

2 years ago

1.4.23

2 years ago

1.4.22

2 years ago

1.4.20

2 years ago

1.3.20

2 years ago

1.3.19

2 years ago

1.3.18

2 years ago

1.3.17

2 years ago

1.3.16

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago