feat: add public notification action routes

This commit is contained in:
Daniel Volz
2026-05-10 23:48:52 +02:00
committed by GitHub
parent ae5d6cc3e8
commit 6a31019fdc
6 changed files with 1246 additions and 7 deletions
+40
View File
@@ -244,6 +244,46 @@ describe("Server Bootstrap", () => {
await app.close();
});
it("should allow browser preflight requests on public notification action routes", async () => {
const origins = ["https://medtest.danielvolz.org"];
const app = Fastify({ logger: false, ajv: documentationSchemaAjv });
await app.register(cors, {
delegator: (request, callback) => {
if (request.raw.url?.startsWith("/notification-actions/")) {
callback(null, {
origin: true,
credentials: false,
methods: ["GET", "HEAD", "POST", "OPTIONS"],
});
return;
}
callback(null, { origin: origins, credentials: true });
},
});
app.post("/notification-actions/:token", async () => ({ ok: true }));
await app.ready();
const response = await app.inject({
method: "OPTIONS",
url: "/notification-actions/demo-token",
headers: {
origin: "https://ntfy.danielvolz.org",
"access-control-request-method": "POST",
"access-control-request-headers": "content-type",
},
});
expect(response.statusCode).toBe(204);
expect(response.headers["access-control-allow-origin"]).toBe("https://ntfy.danielvolz.org");
expect(response.headers["access-control-allow-credentials"]).toBeUndefined();
expect(response.headers["access-control-allow-methods"]).toContain("OPTIONS");
await app.close();
});
it("should register cookie plugin", async () => {
const app = Fastify({ logger: false, ajv: documentationSchemaAjv });
await app.register(cookie, { secret: "test-cookie-secret" });