var express = require("express");
var Mock = require("mockjs")
let data = Mock.mock({
"list|20-100":[
{
"id|+1": 1,
"name": "@cname",
"gender|1": '@string("男女",1)',
"age":'@natural(1,100)',
"address": "@county(true)",
"birth": "@datetime(yyyy-MM-dd)",
"email": '@email',
'phone|1': /^1[3|4|5|8][0-9]\d{8}$/
}
]
})
var app = new express();
app.all("*",(req,res,next)=>{
res.header("Access-Control-Allow-Origin","*")
// res.header("Access-Control-Allow-Methods","get,port,patch,put,delete")
next()
})
// 解析参数的
app.get("/",(req,res) =>{
res.send(data)
})
app.post("/user",(req,res) =>{
let obj = {
code: '200',
status: 'ok',
userInfo: {
name: '张三',
age: 18,
gender: "男"
}
}
res.send(obj)
})
let port = 9527
// 浏览器只能测试get请求
app.listen(port,()=>{
console.log(`端口启动 http://localhost:${port}`);
})
nodejs-express+mock数据
最新推荐文章于 2022-11-10 20:18:02 发布