Ryan Freeman bf69b53bfc
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 3m11s
Add comments
2025-03-21 16:48:08 +00:00

22 lines
854 B
TypeScript

import {createClient} from '@/lib/supabase/server'
export async function GET(request: Request, {params}: { params: Promise<{ slug: string }> }) {
const {slug} = await params
if (typeof slug !== 'undefined') {
try {
const supabase = await createClient()
const {data: record, error} = await supabase
.from('analytics')
.select('*, articles!inner(*)')
.eq('articles.slug', slug)
if (record !== null) {
const [{views}] = record
return new Response(JSON.stringify({views: views}), {status: 200})
}
} catch (e) {
return new Response(JSON.stringify({status: 'Internal Server Error'}), {status: 500})
}
}
return new Response(JSON.stringify({status: 'Not Found'}), {status: 404})
}