yyq-member
v1.0.0
Published
```js const fs=require('fs'); const path=require('path'); const http=require('http'); const url=require('url'); const static="public"; const s=http.createServer((req,res)=>{ let pathname=url.parse(req.url).pathname; if(pathname==="/"){
Downloads
2
Readme
#登录注册
const fs=require('fs');
const path=require('path');
const http=require('http');
const url=require('url');
const static="public";
const s=http.createServer((req,res)=>{
let pathname=url.parse(req.url).pathname;
if(pathname==="/"){
pathname="index.html"
}
if(path.extname(pathname)){
if(fs.existsSync(path.join(static,pathname))){
res.end(fs.readFileSync(path.join(static,pathname)))
}
}else{
if(pathname==="/api/list"){
let body="";
req.on('data',chunk=>{
body+=chunk;
})
req.on('end',()=>{
let{user,pass}=JSON.parse(body);
let data=require('./user.json');
let flag=data.some(item=>item.user===user&&item.pass===pass);
if(flag){
res.end('1')
}else{
res.end('0')
}
})
}
if(pathname==="/api/li"){
let body="";
req.on('data',chunk=>{
body+=chunk;
})
req.on('end',()=>{
let{user,pass}=JSON.parse(body);
let data=require('./user.json');
let flag=data.some(item=>item.user===user);
if(flag){
res.end('0')
}else{
data.push(JSON.parse(body));
fs.writeFileSync('user.json',JSON.stringify(data))
res.end('1')
}
})
}
}
})
s.listen(8888,()=>console.log('人生太难了'))