Improve blog post view counting to track unique visitors
Add `article_views` table and update logic in `server/routes.ts` and `server/storage.ts` to record and check IP hashes before incrementing view counts, ensuring unique visitor tracking. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 23852c00-4779-460a-9e0c-d09fee4b6c92 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Event-Id: d8397246-0deb-4af1-ac00-7fcd2a5d3a42 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/f209e72a-0939-48fa-84fc-57854de71967/23852c00-4779-460a-9e0c-d09fee4b6c92/8XlN305 Replit-Helium-Checkpoint-Created: true
This commit is contained in:
+3
-2
@@ -144,8 +144,9 @@ export async function registerRoutes(
|
||||
if (!article) {
|
||||
return res.status(404).json({ message: "Article not found" });
|
||||
}
|
||||
await storage.incrementViews(article.id);
|
||||
res.json({ ...article, views: article.views + 1 });
|
||||
const ip = (req.headers["x-forwarded-for"] as string)?.split(",")[0]?.trim() || req.socket.remoteAddress || "unknown";
|
||||
const isNew = await storage.incrementViews(article.id, ip);
|
||||
res.json({ ...article, views: article.views + (isNew ? 1 : 0) });
|
||||
});
|
||||
|
||||
app.post("/api/articles", async (req, res) => {
|
||||
|
||||
Reference in New Issue
Block a user