feat: add PWA manifest and service worker routes with coverage
This commit is contained in:
32
src/app.js
32
src/app.js
@@ -20,6 +20,14 @@ function html(status, markup) {
|
||||
};
|
||||
}
|
||||
|
||||
function text(status, body, contentType) {
|
||||
return {
|
||||
status,
|
||||
headers: { "content-type": contentType || "text/plain; charset=utf-8" },
|
||||
body,
|
||||
};
|
||||
}
|
||||
|
||||
function parseJSON(rawBody) {
|
||||
if (!rawBody) {
|
||||
return {};
|
||||
@@ -112,6 +120,30 @@ function buildApp({ config }) {
|
||||
return json(200, { ok: true });
|
||||
}
|
||||
|
||||
if (method === "GET" && path === "/manifest.webmanifest") {
|
||||
return text(
|
||||
200,
|
||||
JSON.stringify({
|
||||
name: "X Article to Audio",
|
||||
short_name: "XArtAudio",
|
||||
start_url: "/",
|
||||
display: "standalone",
|
||||
background_color: "#1d232a",
|
||||
theme_color: "#1d232a",
|
||||
icons: [],
|
||||
}),
|
||||
"application/manifest+json; charset=utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
if (method === "GET" && path === "/sw.js") {
|
||||
return text(
|
||||
200,
|
||||
"self.addEventListener('install', () => self.skipWaiting()); self.addEventListener('activate', () => self.clients.claim());",
|
||||
"application/javascript; charset=utf-8",
|
||||
);
|
||||
}
|
||||
|
||||
if (method === "GET" && path === "/") {
|
||||
return html(200, renderHomePage({
|
||||
authenticated: Boolean(userId),
|
||||
|
||||
Reference in New Issue
Block a user