import { createFileRoute } from "@tanstack/react-router"; import { useEffect, useState } from "react"; export const Route = createFileRoute("/")({ component: Home, }); // Public URL of the backend, injected at build time via Vite. // Falls back to localhost for `vite dev`. const API_URL = import.meta.env.VITE_API_URL ?? "http://localhost:3000"; type Hello = { message: string; timestamp: string }; function Home() { const [data, setData] = useState(null); const [error, setError] = useState(null); useEffect(() => { fetch(`${API_URL}/api/hello`) .then((r) => { if (!r.ok) throw new Error(`HTTP ${r.status}`); return r.json() as Promise; }) .then(setData) .catch((e) => setError(String(e))); }, []); return (

test-app-stack

TanStack Start frontend talking to an ElysiaJS (Bun) backend.

Backend connection

API URL: {API_URL}

{error &&

❌ {error}

} {!error && !data &&

Connecting…

} {data && ( <>

{data.message}

at {data.timestamp}

)}
); }