Fix sending incorrect content type for articles

This commit is contained in:
Shadowfacts 2019-06-30 15:16:08 -04:00
parent 4743d69f95
commit 43a3fc1a69
Signed by untrusted user: shadowfacts
GPG Key ID: 94A5AB95422746E5
1 changed files with 7 additions and 3 deletions

View File

@ -59,9 +59,11 @@ export async function toFederate(db: Database): Promise<[string, Article][]> {
export function route(router: Router) { export function route(router: Router) {
router.use("/:category/:year/:slug/", (req, res, next) => { 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(); next();
} else { } else if (best === "application/activity+json") {
const db = <Database>req.app.get("db") const db = <Database>req.app.get("db")
db.get("SELECT article_doc FROM articles WHERE id = $id", { db.get("SELECT article_doc FROM articles WHERE id = $id", {
$id: `/${req.params.category}/${req.params.year}/${req.params.slug}/` $id: `/${req.params.category}/${req.params.year}/${req.params.slug}/`
@ -70,9 +72,11 @@ export function route(router: Router) {
res.status(500).end(err); res.status(500).end(err);
return; return;
} }
res.type("application/json"); res.type("application/activity+json");
res.end(result.article_doc); res.end(result.article_doc);
}); });
} else {
res.status(415).end("No acceptable content-type given. text/html or application/activity+json are supported");
} }
}); });
} }