From cd57f2c5ac736ee99191d152543ac393ffd04d13 Mon Sep 17 00:00:00 2001 From: Paul Robert Lloyd Date: Wed, 1 Nov 2023 23:10:39 +0000 Subject: [PATCH] feat(indiekit): web app manifest --- packages/indiekit/lib/controllers/manifest.js | 22 +++++++++++++++++++ packages/indiekit/lib/routes.js | 4 ++++ .../tests/integration/200-manifest.js | 16 ++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 packages/indiekit/lib/controllers/manifest.js create mode 100644 packages/indiekit/tests/integration/200-manifest.js diff --git a/packages/indiekit/lib/controllers/manifest.js b/packages/indiekit/lib/controllers/manifest.js new file mode 100644 index 000000000..ea0b117ef --- /dev/null +++ b/packages/indiekit/lib/controllers/manifest.js @@ -0,0 +1,22 @@ +export const get = async (request, response) => { + const { application } = request.app.locals; + + return response.type("application/manifest+json").json({ + $schema: "https://json.schemastore.org/web-manifest-combined.json", + lang: application.locale, + name: application.name, + theme_color: application.themeColor, + icons: [ + { + src: "assets/icon.svg", + sizes: "32x32", + type: "image/svg+xml", + }, + { + src: "assets/app.png", + sizes: "1024x1024", + type: "image/png", + }, + ], + }); +}; diff --git a/packages/indiekit/lib/routes.js b/packages/indiekit/lib/routes.js index 78160879d..bf623d6f9 100644 --- a/packages/indiekit/lib/routes.js +++ b/packages/indiekit/lib/routes.js @@ -5,6 +5,7 @@ import rateLimit from "express-rate-limit"; import * as assetsController from "./controllers/assets.js"; import * as feedController from "./controllers/feed.js"; import * as homepageController from "./controllers/homepage.js"; +import * as manifestController from "./controllers/manifest.js"; import * as pluginController from "./controllers/plugin.js"; import * as sessionController from "./controllers/session.js"; import * as statusController from "./controllers/status.js"; @@ -50,6 +51,9 @@ export const routes = (indiekitConfig) => { // Feed router.get("/feed.jf2", feedController.jf2); + // Web App Manifest + router.get("/app.webmanifest", manifestController.get); + // Session router.get("/session/login", limit, sessionController.login); router.post("/session/login", limit, indieauth.login()); diff --git a/packages/indiekit/tests/integration/200-manifest.js b/packages/indiekit/tests/integration/200-manifest.js new file mode 100644 index 000000000..8a3da0fb8 --- /dev/null +++ b/packages/indiekit/tests/integration/200-manifest.js @@ -0,0 +1,16 @@ +import test from "ava"; +import supertest from "supertest"; +import { testServer } from "@indiekit-test/server"; + +test("Returns Web App Manifest", async (t) => { + const server = await testServer(); + const request = supertest.agent(server); + const result = await request.get("/app.webmanifest"); + + t.is(result.status, 200); + t.is(result.type, "application/manifest+json"); + t.is(result.body.name, "Test configuration"); + t.truthy(result.body.icons); + + server.close(t); +});