yyq-exdemo
v1.0.0
Published
```js //配置 const express=require('express'); const app=express(); const fs=require('fs');
Downloads
2
Readme
//配置
const express=require('express');
const app=express();
const fs=require('fs');
//开启服务
app.listen(8080,()=>{console.log('开启')});
//静态资源
app.use(express.static('public',{index:"index.html"}));
//处理json
app.use(express.json())
//登录接口
app.post('/api/login',(req,res)=>{
let{user,pass,num,yzm}=req.body;//结构
let data=require('./mock/user.json');
let flay=data.some(item=>item.user===user&&item.pass===pass)
if(num!==yzm){
res.end('0');
return;
}
if(flay){
res.end('1')
}else{
res.end('0')
}
})
//注册接口
app.post('/api/list',(req,res)=>{
let{user,pass,num,yzm}=req.body;//结构
let data=require('./mock/user.json');
let flay=data.some(item=>item.user===user)
if(num!==yzm){
res.end('0');
return;
}
if(flay){
res.end('0')
}else{
data.push(req.body)
fs.writeFileSync('./mock/user.json',JSON.stringify(data))
res.end('1')
}
})