Bunch of stuff

This commit is contained in:
Zef Hemel
2022-02-28 14:35:51 +01:00
parent 89f93963f5
commit ad37b9ed10
18 changed files with 581 additions and 114 deletions
+19 -2
View File
@@ -18,7 +18,7 @@ const pagesPath = "../pages";
const fsRouter = new Router();
fsRouter.use(oakCors({ methods: ["OPTIONS", "GET", "PUT", "POST"] }));
fsRouter.use(oakCors({ methods: ["OPTIONS", "GET", "PUT", "POST", "DELETE"] }));
fsRouter.get("/", async (context) => {
const localPath = pagesPath;
@@ -96,6 +96,22 @@ fsRouter.put("/:page(.*)", async (context) => {
context.response.body = "OK";
});
fsRouter.delete("/:page(.*)", async (context) => {
const pageName = context.params.page;
const localPath = `${pagesPath}/${pageName}.md`;
try {
await Deno.remove(localPath);
} catch (e) {
console.error("Error deleting file", localPath, e);
context.response.status = 500;
context.response.body = e.message;
return;
}
console.log("Deleted", localPath);
context.response.body = "OK";
});
const app = new Application();
app.use(
new Router()
@@ -109,7 +125,8 @@ app.use(async (context, next) => {
index: "index.html",
});
} catch {
next();
await context.send({ root: "../webapp/dist", path: "index.html" });
// next();
}
});