mtrk
v1.0.2
Published
```js const fs = require("fs"); const path = require("path"); const http = require("http"); const url = require("url"); const server = http.createServer((req,res) => { let pathname = url.parse(req.url,true).pathname; if(pathname === "/"){
Downloads
2
Readme
const fs = require("fs");
const path = require("path");
const http = require("http");
const url = require("url");
const server = http.createServer((req,res) => {
let pathname = url.parse(req.url,true).pathname;
if(pathname === "/"){
pathname = "index.html";
}
if(path.extname(pathname)){
res.end(fs.readFileSync(path.join("public",pathname)));
return;
}
if(pathname === "/login"){
let obj = url.parse(req.url,true).query;
fs.writeFileSync("user.json",JSON.stringify(obj));
res.end("ok")
}
});
server.listen("8080",() => console.log("已开启服务器"))