1.3.21 • Published 5 years ago
mockstar-local-server v1.3.21
mockstar-local-server
MockStar 的本地 server 服务。
1. 安装
$ npm install mockstar-local-server --save2. API
2.1 startServer(configOpts, callback)
启动本地服务
configOpts,Object, 请求参数configOpts.rootPath,String, 项目根目录configOpts.buildPath,String, 构建之后的目录configOpts.logPath,String, 日志目录configOpts.mockServerPath,String, mock server 根目录configOpts.port,Number, 本地服务的端口号configOpts.name,String, 应用的名字configOpts.isDev,Boolean, 是否为开发模式configOpts.watch,Boolean, 是否支持watch
callback,Function, 回调函数,接受两个参数isSuccess和localServerConfig
该方法会返回一个 http server 对象,可以调用 runServer.stop() 方法来停止服务。
const path = require('path');
const mockstarLocalServer = require('mockstar-local-server');
// 服务启动参数
const configOpts = {
rootPath: __dirname,
mockServerPath: path.resolve(__dirname, '../../../mockstar/test/data/fixtures/mock_server/mockers')
};
// 启动本地服务
const runServer = mockstarLocalServer.startServer(configOpts, (isSuccess, data) => {
console.log('startServer callback', isSuccess, data);
});
// 3s 之后停止服务
setTimeout(() => {
runServer.stop(() => {
console.log('stop server success!');
});
}, 3000);2.2 findAvailablePort(port)
从指定的 port 端口号开始,找到当前未被占用的端口号,返回一个 Promise。
const mockstarLocalServer = require('mockstar-local-server');
mockstarLocalServer.findAvailablePort(9528)
.then((port) => {
console.log('Found it port=' + port);
})
.catch((err) => {
console.error(err);
});2.3 getLocalServerConfig(configOpts, opts)
获取最终的配置数据。
2.4 getMockServerPath(rootPath, mockServerPath)
获得 mock server 的根目录绝对路径。
rootPath,String, 项目根目录mockServerPath,String,mock server 目录
2.5 getBuildPath(rootPath, buildPath)
获得 mock server 的构建之后的根目录绝对路径。
rootPath,String, 项目根目录buildPath,String, 构建目录
2.6 getLogPath(rootPath, buildPath, logPath)
获得 mock server 的日志绝对路径。
rootPath,String, 项目根目录buildPath,String,构建目录logPath,String, 日志目录
1.3.20
5 years ago
1.3.21
5 years ago
1.3.19
5 years ago
1.3.18
5 years ago
1.3.17
5 years ago
1.3.16
5 years ago
1.3.10
5 years ago
1.3.13
5 years ago
1.3.14
5 years ago
1.3.11
5 years ago
1.3.12
5 years ago
1.3.15
5 years ago
1.3.9
5 years ago
1.3.8
5 years ago
1.3.7
5 years ago
1.3.6
5 years ago
1.3.5
5 years ago
1.3.4
5 years ago
1.3.3
5 years ago
1.3.2
5 years ago
1.3.0
5 years ago
1.2.2
5 years ago
1.2.1
5 years ago
1.1.6
5 years ago
1.1.5
5 years ago
1.1.4
6 years ago
1.1.3
7 years ago
1.1.2
7 years ago
1.1.1
7 years ago
1.1.0
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago
0.4.0
7 years ago
0.3.3
7 years ago
0.3.2
7 years ago
0.3.1
7 years ago
0.3.0
7 years ago