You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
37 lines
1.0 KiB
4 years ago
|
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
|