diff --git a/package.json b/package.json index 0e3c439..62c52cf 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "scripts": { - "start": "node --expose-gc --max-old-space-size=200 ./bin/www", + "start": "node ./bin/www", "dev": "nodemon --expose-gc --max-old-space-size=200 ./bin/www", "test": "nyc -a mocha --recursive", "deploy": "flyctl deploy", diff --git a/routes/danmaku.js b/routes/danmaku.js index 860e292..e47ddaf 100644 --- a/routes/danmaku.js +++ b/routes/danmaku.js @@ -94,18 +94,27 @@ async function index(req, res) { const names = list.map(item => item.name); const domains = list.map(item => item.domain); const path = req.protocol + "://" + req.headers.host + req.originalUrl; - const resolve_info = await db.accessCountQuery() - const hotlist = await db.hotlistQuery() res.render("danmaku", { path, urls, names, domains, - resolve_info, - hotlist }); } +router.get("/api/home-data", async (req, res) => { + try { + const [resolve_info, hotlist] = await Promise.all([ + db.accessCountQuery(), + db.hotlistQuery() + ]); + res.json({ resolve_info, hotlist }); + } catch (err) { + console.error(err); + res.status(500).json({ error: "查询失败" }); + } +}); + /* GET home page. */ router.get("/", async function (req, res) { db.accessInsert({ diff --git a/views/danmaku.ejs b/views/danmaku.ejs index 91c0772..ddf198e 100644 --- a/views/danmaku.ejs +++ b/views/danmaku.ejs @@ -41,14 +41,7 @@

最近一天下载热榜

@@ -97,14 +90,41 @@
- 今日解析量:<%= resolve_info.today_visited %> | - 昨日解析量:<%= resolve_info.lastday_visited %> | - 近一个月解析量:<%= resolve_info.month_visited %> + 今日解析量:加载中... | + 昨日解析量:加载中... | + 近一个月解析量:加载中...
+ \ No newline at end of file