import { NextApiRequest , NextApiResponse } from "next" ; import { PostDetails } from "@/typings/blog" ; import { supabase } from "@/utils/supabaseClient" ; api export default async ( req , res ) => { if ( req . method === "GET" ) { const { slug } = req . query ; if ( Array . isArray ( slug ) ) { res . status ( 200 ) . send ( { view_count : 1 , message : "This isn't supported yet, nice try!" } ) ; } else { const { data , error } = await supabase . from < PostDetails > ( "page_details" ) . select ( "view_count" ) . eq ( "slug" , slug ) . limit ( 1 ) . single ( ) ; if ( error ) { res . status ( 200 ) . send ( { view_count : 0 } ) ; } else { const { view_count } = data ?? { view_count : 0 } ; res . status ( 200 ) . send ( { view_count } ) ; } } } else { res . status ( 400 ) . send ( "Bad request" ) ; } } ;