From 8b7301d0daa846f93cac7430a0efa468a1d89470 Mon Sep 17 00:00:00 2001 From: Web-serfer Date: Mon, 27 Apr 2026 21:00:34 +0500 Subject: [PATCH] Change POST to GET for view counter --- frontend/src/layouts/ArticleLayout.astro | 2 +- frontend/src/pages/api/increment-views.ts | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/frontend/src/layouts/ArticleLayout.astro b/frontend/src/layouts/ArticleLayout.astro index 82f3a9a..446a09c 100644 --- a/frontend/src/layouts/ArticleLayout.astro +++ b/frontend/src/layouts/ArticleLayout.astro @@ -315,7 +315,7 @@ const { if (viewsEl?.dataset?.postId) { const postId = viewsEl.dataset.postId; - fetch(`/api/increment-views?postId=${postId}`, { method: 'POST' }) + fetch(`/api/increment-views?postId=${postId}`) .then(res => res.json()) .then(data => { if (data.views !== undefined) { diff --git a/frontend/src/pages/api/increment-views.ts b/frontend/src/pages/api/increment-views.ts index c7e9986..063b977 100644 --- a/frontend/src/pages/api/increment-views.ts +++ b/frontend/src/pages/api/increment-views.ts @@ -46,18 +46,7 @@ function jsonResponse(data: object, status = 200): Response { }); } -export const POST: APIRoute = async ({ request, url }) => { - if (request.method === 'OPTIONS') { - return new Response(null, { - status: 204, - headers: { - 'Access-Control-Allow-Origin': '*', - 'Access-Control-Allow-Methods': 'POST, OPTIONS', - 'Access-Control-Allow-Headers': 'Content-Type', - } - }); - } - +export const GET: APIRoute = async ({ request, url }) => { console.log('[Increment Views] PB_URL:', POCKETBASE_URL); try {