var express = require('express'); var router = express.Router(); var Mock = require("mockjs") router.post('/login',function(req, res, next) { console.log(req.body); //调用mock方法模拟数据 var data = Mock.mock({ code:/200|500/ } ) if(data.code==='200'){ data={...data,...{result:'OK',message:'登陆成功',body:{username:Mock.Random.cname(),sessionId:Mock.Random.guid()}}} }else{ data={...data,...{result:'FAIL',message:'登陆失败'}} } return res.json(data); }) router.post('/register',function(req, res, next) { console.log(req.body); //调用mock方法模拟数据 var data = Mock.mock({ code:/200|500/, result:function (context){ return context.context.root.code==='200'?'OK':'FAIL' }, message:function (context){ return context.context.root.code==='200'?'注册成功':'注册失败' } } ) return res.json(data); }) module.exports=router