actually serve pages

This commit is contained in:
Moon Man 2023-12-26 06:56:11 -05:00
parent 6f2f5843c0
commit 468878bdaf
1 changed files with 21 additions and 2 deletions

View File

@ -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);