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 };
}
});
3 Replies
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.
file:
server/api/hello/[id].ts
from the docskk thanks i fugure it out with your help