From 43a3fc1a695c4aba11581223065b6e0e3d194c51 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 30 Jun 2019 15:16:08 -0400 Subject: [PATCH] Fix sending incorrect content type for articles --- lib/activitypub/articles.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/activitypub/articles.ts b/lib/activitypub/articles.ts index 8d90d87..bb70ed7 100644 --- a/lib/activitypub/articles.ts +++ b/lib/activitypub/articles.ts @@ -59,9 +59,11 @@ export async function toFederate(db: Database): Promise<[string, Article][]> { export function route(router: Router) { router.use("/:category/:year/:slug/", (req, res, next) => { - if (req.accepts("text/html")) { + const best = req.accepts(["text/html", "application/activity+json"]); + console.log(best); + if (best === "text/html") { next(); - } else { + } else if (best === "application/activity+json") { const db = req.app.get("db") db.get("SELECT article_doc FROM articles WHERE id = $id", { $id: `/${req.params.category}/${req.params.year}/${req.params.slug}/` @@ -70,9 +72,11 @@ export function route(router: Router) { res.status(500).end(err); return; } - res.type("application/json"); + res.type("application/activity+json"); res.end(result.article_doc); }); + } else { + res.status(415).end("No acceptable content-type given. text/html or application/activity+json are supported"); } }); } \ No newline at end of file