From 27dbc021b444d62396d9e86f1c4e8fa6a162d747 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Mon, 4 Jul 2022 21:58:27 +0800 Subject: [PATCH] Add standalone manifest.json for each status page. Close #1668 --- server/model/status_page.js | 5 ++++ server/routers/status-page-router.js | 38 ++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/server/model/status_page.js b/server/model/status_page.js index 5bb82333..82d184bf 100644 --- a/server/model/status_page.js +++ b/server/model/status_page.js @@ -45,6 +45,8 @@ class StatusPage extends BeanModel { $("link[rel=icon]") .attr("href", statusPage.icon) .removeAttr("type"); + + $("link[rel=apple-touch-icon]").remove(); } const head = $("head"); @@ -61,6 +63,9 @@ class StatusPage extends BeanModel { `); + // manifest.json + $("link[rel=manifest]").attr("href", `/api/status-page/${statusPage.slug}/manifest.json`); + return $.root().html(); } diff --git a/server/routers/status-page-router.js b/server/routers/status-page-router.js index 465afdf8..de075db8 100644 --- a/server/routers/status-page-router.js +++ b/server/routers/status-page-router.js @@ -107,4 +107,42 @@ router.get("/api/status-page/heartbeat/:slug", cache("1 minutes"), async (reques } }); +// Status page's manifest.json +router.get("/api/status-page/:slug/manifest.json", cache("1440 minutes"), async (request, response) => { + allowDevAllOrigin(response); + let slug = request.params.slug; + + try { + // Get Status Page + let statusPage = await R.findOne("status_page", " slug = ? ", [ + slug + ]); + + if (!statusPage) { + response.statusCode = 404; + response.json({ + msg: "Not Found" + }); + return; + } + + // Response + response.json({ + "name": statusPage.title, + "start_url": "/status/" + statusPage.slug, + "display": "standalone", + "icons": [ + { + "src": statusPage.icon, + "sizes": "128x128", + "type": "image/png" + } + ] + }); + + } catch (error) { + send403(response, error.message); + } +}); + module.exports = router;