Nighttime Peanut Migrations

    similar-server-mock-server

    0.1.2 • Public • Published

    mock-server

    安装

    npm install --save similar-server-mock-server
    

    使用 mock-start.js

    import 'similar-server-mock-server';
    
    // 或者
    
    import { Application } from 'similar-server'; 
    import { start } from 'similar-server-mock-server/dist/mock';
    
    start(Application());
    

    配置文件 .babelrc

    {
        "plugins": [
            "transform-decorators-legacy"
        ],
        "presets": ["env"]
    }
    

    启动参数 package.json

    {
        // ...
        "mock": "nodemon mock-server.js --exec babel-node",
        "mockConfig": {
            "mockDir": "mock",
            "serverPort": "9000"
        }
        // ...
    }
    

    配置请求 config.mock.js

    export default {
        // Support type as Object and Array
        'GET /api/users': { users: [1,2] },
    
        // Method like GET or POST can be omitted
        '/api/users/1': { id: 1 },
    
        // Support for custom functions, the API is the same as express@4
        'POST /api/users/create': (req, res) => { res.end('OK'); },
    };
    

    安装启动依赖

    npm install --save-dev nodemon babel-cli babel-plugin-transform-decorators-legacy babel-preset-env
    

    启动

    babel-node mock-start.js
    // 或者
    nodemon mock-server.js --exec babel-node

    Install

    npm i similar-server-mock-server

    DownloadsWeekly Downloads

    2

    Version

    0.1.2

    License

    MIT

    Unpacked Size

    8.47 kB

    Total Files

    5

    Last publish

    Collaborators

    • liuhong1happy