Skip to content

Commit

Permalink
feat(indiekit): web app manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Nov 1, 2023
1 parent 4bb7cc1 commit cd57f2c
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/indiekit/lib/controllers/manifest.js
Original file line number Diff line number Diff line change
@@ -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",
},
],
});
};
4 changes: 4 additions & 0 deletions packages/indiekit/lib/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions packages/indiekit/tests/integration/200-manifest.js
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit cd57f2c

Please sign in to comment.