Fix sending incorrect content type for articles
This commit is contained in:
parent
4743d69f95
commit
43a3fc1a69
|
@ -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 = <Database>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");
|
||||
}
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue