diff --git a/src/index.ts b/src/index.ts index ed2fc63..75e29ed 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,8 +1,10 @@ +import { readFileSync } from "fs"; import express from "express"; import ActivitypubExpress from "activitypub-express"; import { get as getOutbox } from "./outbox.js"; import { get as getUserByNickname, getId as getUserId } from "./user.js"; import { Routes, fillRoute } from "./router.js"; +import { getBySlug } from "./article.js"; const port = parseInt(process.env.port || "8080"); const app = express(); @@ -88,10 +90,27 @@ app.get(Routes.actor, async (req, res) => { } }); -app.get("/:slug", (req, res) => { +app.get("/:slug.html", async (req, res) => { + const article = await getBySlug(req.params.slug); + + if (!article || article.deleted) { + res.status(404).send("not found"); + } + else { + const filename = article.file.replace(/\.md$/, ".html"); + res.sendFile(filename); + } }); -app.get("/:slug.md", (req, res) => { +app.get("/:slug.md", async (req, res) => { + const article = await getBySlug(req.params.slug); + + if (!article || article.deleted) { + res.status(404).send("not found"); + } + else { + res.sendFile(article.file); + } }); const SERVER = app.listen(port);