October 23, 2023
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { set } from "https://esm.town/v/std/set?v=11";
let { guestbookMessages } = await import("https://esm.town/v/vtdocs/guestbookMessages");
export const guestbook = async (req: express.Request, res: express.Response) => {
const esc = (await import("npm:escape-html@1.0.3")).default;
if (guestbookMessages === undefined) {
guestbookMessages = [];
}
if (req.method === "GET") {
return res.json(guestbookMessages);
}
if (req.body.name === undefined || req.body.text === undefined) {
return res.status(400);
}
guestbookMessages.push({
name: esc(req.body.name),
text: esc(req.body.text),
});
await set(
"guestbookMessages",
guestbookMessages,
);
return res.status(200);
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023