1.0.0 • Published 3 months ago

yyq-exagin v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 months ago
const express=require('express');
const app=express();
const fs=require('fs');

app.listen(8080,()=>console.log('走向前端大佬的一天'))
app.use(express.static('public',{index:"index.html"}))
app.use(express.json())
//登陆接口
app.post('/api/login',(req,res)=>{
    let{user,pass,num,yzm}=req.body;
    let data=JSON.parse(fs.readFileSync('./mock/user.json'));
    let flay=data.some(item=>item.user===user&&item.pass===pass)
    if(num!==yzm){
        res.send({
            code:"2"
        });
        return;
    }
    if(flay){
      res.send({
          code:"1"
      });
    }else{
        res.send({
            code:"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.send({
            code:"2" 
        });
        return;
    }
    if(flay){
        res.send({
            code:"0"
         
        });
    }else{
        data.push(req.body);
        fs.writeFileSync('./mock/user.json',JSON.stringify(data));
        res.send({
            code:"1"
        });
    } 
})
1.0.0

3 months ago