Public
Express
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { likesData } from "https://esm.town/v/merlin/likesData";
import { auth } from "https://esm.town/v/merlin/auth";
export const GETLikes = (req: express.Request, res: express.Response) => {
auth(req, res);
if (req.method !== "GET") {
res.status(400).send("Bad request");
}
const posts = likesData;
const postSlug = req.query.postSlug as string ?? "";
const deviceId = req.get("Authorization").replace("Bearer ", "");
const likes = posts[postSlug] ?? [];
return res.json({
count: likes.length,
currentUserHasLiked: likes.includes(deviceId),
});
};
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!
merlin-getlikes.express.val.run
October 23, 2023