0 Star 0 Fork 0

minglie/ming_api_mock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
index.js 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
minglie 提交于 2020-12-26 11:26 . aa
M = require("ming_node")
var os = require('os');
var args = process.argv.splice(2)
let argsPath=args[0] || "./";
let port= args[1] ||8888;
M.__default_file={};
M.__default_file["__default_server.js"]="console.log(1)";
M.__default_file["__default_index.html"]="hello";
staticPath=argsPath.replace(/\\/g,"/") || "./" ;
console.log("static path="+staticPath)
var app = M.server();
app.listen(port);
app.set("views", staticPath);
M.log_path = staticPath+"M.log";
M.map_path =staticPath+ "M_map.json";
M.database_path = staticPath+"M_database.json";
M.endRun=()=>{};
M.beforeRun=()=>{return true};
M.beforeWriteFile=()=>{return true};
app.get("/", async (req, res) => {
res.writeHead(200, { "Content-Type": "text/html;charset='utf-8'" });
res.write(indexHtml);
res.end();
})
app.post("/_run_", async (req, res) => {
try {
if(M.beforeWriteFile(req.url)){
//默认__default_不必存储
if(req.params.file.startsWith("__default_")){
M.__default_file[req.params.file]=req.params.fun;
}else{
M.writeFile(staticPath + req.params.file, req.params.fun);
}
}
if( M.beforeRun(req.url))
{
if (req.params.file.endsWith(".js")) {
eval(req.params.fun)
}
}
res.send(M.result("ok"))
M.endRun(req.params.file);
} catch (e) {
console.error(e)
res.send(M.result("error", false))
}
})
app.get("/_curFileList",async (req,res)=>{
let s1="__default_server.js\n__default_index.html\n";
if(os.type().startsWith("Window")){
s=await M.exec("dir /b "+`"${staticPath}"`)
}else{
s=await M.exec("ls "+staticPath)
}
res.send(M.result(s1+s))
})
app.get("/_t",async (req,res)=>{
console.log(req.params);
res.send(M.result("ok"))
})
eval(M.readFile("./server.js"));
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/minglie/ming_api_mock.git
git@gitee.com:minglie/ming_api_mock.git
minglie
ming_api_mock
ming_api_mock
master

搜索帮助