N
Nuxt5mo ago
QRST

Fetch Server Help!!

I want to get my currentId to server to fetch supabase by id of curretn Id. How do i pass in and use currentid in server to fetch. /component or page file <script setup> const currentId = ref(''); const { data: polls, refresh } = useFetch("/api/polls"); </script> <template> <div> {{ polls }} </div> </template> <style scoped></style> / server/api/polls import { serverSupabaseClient } from "#supabase/server"; export default eventHandler(async (event) => { try { const client = await serverSupabaseClient(event); // const { data, error } = await client.from("polls").select(""); // if (error) { // throw error; // } const { data: polls, pollsDataError } = await client .from("polls") .select("") .order("created_at"); if (pollsDataError) { throw pollsDataError; } return { polls, }; } catch (error) { console.error("Error fetching polls:", error.message); return { error: error.message }; } });
No description
3 Replies
Sam  K
Sam K5mo ago
hey, you can use dynamic params in the server routes https://nuxt.com/docs/guide/directory-structure/server#route-parameters
Nuxt
server/ · Nuxt Directory Structure
The server/ directory is used to register API and server handlers to your application.
Sam  K
Sam K5mo ago
file: server/api/hello/[id].ts
export default defineEventHandler((event) => {
const id = getRouterParam(event, 'id')

return `Hello, ${id}!`
})
export default defineEventHandler((event) => {
const id = getRouterParam(event, 'id')

return `Hello, ${id}!`
})
from the docs
QRST
QRSTOP5mo ago
kk thanks i fugure it out with your help
Want results from more Discord servers?
Add your server