2 Star 5 Fork 0

String-for-100w/String

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.js 2.04 KB
一键复制 编辑 原始数据 按行查看 历史
const Koa = require("koa");
const app = new Koa();
const fs = require("fs");
const path = require("path");
const router = require("koa-router")();
const serve = require("koa-static");
const mount = require("koa-mount");
const pathList = require("./public/services/pagePath.js");
const getSvg = require("./lib/getSvg.js");
const http = require("http");
const postList = require("./lib/postList.js");
app.use(mount("/public", serve(__dirname + "/public")));
const selfY = require("./lib/render.js");
selfY.setDirName(__dirname);
selfY.setLayout("/index.html");
selfY.setStatic("/public/pages/static/index.html");
router.get("/", async (ctx, next) => {
ctx.response.redirect('/home');
});
router.get("/sw.js", async (ctx, next) => {
ctx.type = "text/javascript";
ctx.body = fs.readFileSync(path.join(__dirname, "/sw.js"), { encoding: "utf8"});
});
router.get("/manifest.json", async (ctx, next) => {
ctx.type = "text/json";
ctx.body = fs.readFileSync(path.join(__dirname, "/manifest.json"), { encoding: "utf8"});
});
router.get("/index-home.html", async (ctx, next) => {
ctx.type = "text/html";
ctx.body = fs.readFileSync(path.join(__dirname, "/index-home.html"), { encoding: "utf8"});
});
router.get("/svg", async (ctx, next) => {
const size = ctx.query.size, page = ctx.query.page;
ctx.status = 200;
ctx.body = getSvg.getList(size, page);
});
postList.forEach(item => {
if (item.url && item.feeback) router.post(item.url, item.feeback);
})
pathList.forEach(item => {
router.get(item.url, async (ctx, next) => {
ctx.status = 200;
ctx.type = "html";
if (item.name === "home") item.isOrigin = false;
ctx.body = await selfY.render(item.name, item.js.slice(0, -2) + "html", item);
});
})
app.use(router.routes())
.use(router.allowedMethods());
app.use(async (ctx, next) =>{
ctx.status = 200;
ctx.type = "html";
ctx.body = await selfY.render("error", "/public/pages/error/index.html");
});
var server = http.createServer(app.callback());
server.listen(3004);
console.log("localhost:3004")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/string-for-100w/string.git
git@gitee.com:string-for-100w/string.git
string-for-100w
string
String
master

搜索帮助