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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
| const Koa = require("koa"); const router = require("koa-router")(); const parser = require("koa-parser"); const nunjucks = require("nunjucks"); const views = require("koa-views");
const app = new Koa();
app.use(parser());
app.use(views(__dirname + "/views", { map: { html: "nunjucks" } }));
router.get("/", async (ctx) => { let docList = [ "中式浪漫!闭幕式折柳送别运动员", "成都新增1例本土确诊", "冬奥闭幕式中国结创意太绝了", "开幕式小雪花来到闭幕式了", "羽生结弦与金博洋一起做滑跪" ]; let vidList = [ "中式浪漫!闭幕式折柳送别运动员", "成都新增1例本土确诊", "冬奥闭幕式中国结创意太绝了", "开幕式小雪花来到闭幕式了", "羽生结弦与金博洋一起做滑跪" ]; let picList = [ "中式浪漫!闭幕式折柳送别运动员", "成都新增1例本土确诊", "冬奥闭幕式中国结创意太绝了", "开幕式小雪花来到闭幕式了", "羽生结弦与金博洋一起做滑跪" ]; await ctx.render("index", { docListTitle: "docListTitle", picListTitle: "picListTitle", vidListTitle: "vidListTitle", docList, vidList, picList, isLogin: false, }) })
router.get("/pictures", async (ctx) => { await ctx.render("index", { title: "pictures", }) })
router.get("/videos", async (ctx) => { await ctx.render("index", { title: "videos", }) })
router.post("/login", async (ctx) => { let _username = "admin"; let _password = "123456"; let username = ctx.request.body.username; let password = ctx.request.body.password; if (username === "" || password === "") { ctx.body = `<script>alert("Please restart input!"); location.href = "./";</script> `; } else if (_username === username && _password === password) { await ctx.render("login", { title: "Log in", username, password, dsc: "登录成功!", isLogin:true }); myUsername = username; } else { await ctx.render("login", { title: "Log in", dsc: "登录失败!" }); } });
app.use(router.routes());
app.listen(3000, () => { console.log("server listening"); })
|