Skip to content
Snippets Groups Projects
Commit 4ec5b0bb authored by Tim-Luca Taxis's avatar Tim-Luca Taxis
Browse files

changed

parent e138540a
No related branches found
No related tags found
1 merge request!4added vercel integration
...@@ -4,7 +4,7 @@ import useSWR from 'swr'; ...@@ -4,7 +4,7 @@ import useSWR from 'swr';
const fetcher = url => fetch(url).then(res => res.json()); const fetcher = url => fetch(url).then(res => res.json());
const FruitList = () => { const FruitList = () => {
const { data: fruits, isLoading, error, mutate } = useSWR('/api/list-fruits', fetcher, { const { data: fruits, error } = useSWR('/api/list-fruits', fetcher, {
revalidateOnFocus: false, revalidateOnFocus: false,
revalidateOnReconnect: false, revalidateOnReconnect: false,
}); });
...@@ -13,13 +13,13 @@ const FruitList = () => { ...@@ -13,13 +13,13 @@ const FruitList = () => {
return <p>Failed to fetch</p>; return <p>Failed to fetch</p>;
} }
if (isLoading) { if (!fruits) {
return <p>Loading fruits...</p>; return <p>Loading fruits...</p>;
} }
return ( return (
<ul> <ul>
{fruits && fruits.length > 0 ? ( {fruits.length > 0 ? (
fruits.map((fruit, index) => ( fruits.map((fruit, index) => (
<li key={index}> <li key={index}>
{fruit['Deutscher Name']} ({fruit['Lateinischer Name']}), {fruit.Farbe}, {fruit.Herkunft}, {fruit.Kalorien} kcal {fruit['Deutscher Name']} ({fruit['Lateinischer Name']}), {fruit.Farbe}, {fruit.Herkunft}, {fruit.Kalorien} kcal
......
...@@ -3,8 +3,8 @@ import { sql } from '@vercel/postgres'; ...@@ -3,8 +3,8 @@ import { sql } from '@vercel/postgres';
export default async function handler(request, response) { export default async function handler(request, response) {
if (request.method === 'GET') { if (request.method === 'GET') {
try { try {
const fruits = await sql`SELECT * FROM obst;`; const { rows: fruits } = await sql`SELECT * FROM obst;`;
return response.status(200).json(fruits.rows); // Ensure you return the rows return response.status(200).json(fruits);
} catch (error) { } catch (error) {
console.error('Error during request processing:', error); console.error('Error during request processing:', error);
return response.status(500).json({ error: error.message }); return response.status(500).json({ error: error.message });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment