1.3.21 • Published 4 years ago

mockstar-local-server v1.3.21

Weekly downloads
7
License
MIT
Repository
github
Last release
4 years ago

mockstar-local-server

MockStar 的本地 server 服务。

1. 安装

$ npm install mockstar-local-server --save

2. API

2.1 startServer(configOpts, callback)

启动本地服务

  • configOptsObject, 请求参数
    • configOpts.rootPathString, 项目根目录
    • configOpts.buildPathString, 构建之后的目录
    • configOpts.logPathString, 日志目录
    • configOpts.mockServerPathString, mock server 根目录
    • configOpts.portNumber, 本地服务的端口号
    • configOpts.nameString, 应用的名字
    • configOpts.isDevBoolean, 是否为开发模式
    • configOpts.watchBoolean, 是否支持watch
  • callbackFunction, 回调函数,接受两个参数 isSuccesslocalServerConfig

该方法会返回一个 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 的根目录绝对路径。

  • rootPathString, 项目根目录
  • mockServerPathString,mock server 目录

2.5 getBuildPath(rootPath, buildPath)

获得 mock server 的构建之后的根目录绝对路径。

  • rootPathString, 项目根目录
  • buildPathString, 构建目录

2.6 getLogPath(rootPath, buildPath, logPath)

获得 mock server 的日志绝对路径。

  • rootPathString, 项目根目录
  • buildPathString,构建目录
  • logPathString, 日志目录
1.3.20

4 years ago

1.3.21

4 years ago

1.3.19

4 years ago

1.3.18

4 years ago

1.3.17

4 years ago

1.3.16

4 years ago

1.3.10

4 years ago

1.3.13

4 years ago

1.3.14

4 years ago

1.3.11

4 years ago

1.3.12

4 years ago

1.3.15

4 years ago

1.3.9

4 years ago

1.3.8

4 years ago

1.3.7

4 years ago

1.3.6

4 years ago

1.3.5

4 years ago

1.3.4

4 years ago

1.3.3

4 years ago

1.3.2

4 years ago

1.3.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.4.0

6 years ago

0.3.3

6 years ago

0.3.2

6 years ago

0.3.1

6 years ago

0.3.0

6 years ago