1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| const express = require("express"); const fs = require("fs"); const path =require("path");
const app = express();
const mockPath = path.join(__dirname,"mock");
let mockDate = {};
const filename = fs.readdirSync(mockPath);
filename.forEach(item => { console.log(require(path.join(mockPath,item))); Object.assign(mockDate,require(path.join(mockPath,item)));
});
for(let key in mockDate){ let [method,url] = key.split(" "); method = method.toLowerCase(); app[method](url,mockDate[key]); }
app.get("/",(req,res)=>{ console.log("5000监听完毕"); res.send("成功") })
const prot = 5000 app.listen(prot,(err)=>{ console.log(`端口${prot}监听完毕`); })
|