Detalhes do pacote

moc

linkwisdom2200.1.5

mock service

mock, mockJSON, mockservice

readme (leia-me)

moc

前端构造数据服务

安装

npm i moc --save

# global install

sudo npm i moc -g
import moc from 'moc'

const config = {
    mockRoot: __dirname, // 默认项目跟目录
    port: 3000, // 启动端口
    tasks: { // 任务处理函数
        modifyTask (ctx, next) {
            return {
                data: 0,
                message: 'success'
            }
        },
        webTask (ctx, next) {
            let {level, method} = ctx.params
            return `./web/${level}/${method}`
        }
    },
    mapping: { // 请求任务映射关系
        modifyTask: ['**/modify', '**/update'],
        webTask: [
            'web/user/:level/:method'
        ]
    },
    static: {
        direction: __dirname,
        extensions: ['html', 'js', 'css']
    },
    plugins: {
        md: function (ctx, next) {
            // koa handler
            if (ctx.request.path.match(/.md$/)) {
                ctx.response.write('....')
            }
        }
    }
}

mock.start(config)