135));
136137// HTTP vals expect an exported "fetch handler"
138export default app.fetch;
Mr-Carson.cursorrules5 matches
163```
1641655. **fetchTranspiledJavaScript** - Fetch and transpile TypeScript to JavaScript:
166```ts
167const jsCode = await fetchTranspiledJavaScript("https://esm.town/v/username/project/path/to/file.ts");
168```
169242243// Inject data to avoid extra round-trips
244const initialData = await fetchInitialData();
245const dataScript = `<script>
246window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
3003015. **API Design:**
302- `fetch` handler is the entry point for HTTP vals
303- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
304- Properly handle CORS if needed for external access
82const [cookieAndTeaMode, setCookieAndTeaMode] = useState(false);
8384// Fetch images from backend instead of blob storage directly
85useEffect(() => {
86// Set default background color in case image doesn't load
89}
9091// Fetch avatar image
92fetch("/api/images/stevens.jpg")
93.then((response) => {
94if (response.ok) return response.blob();
103});
104105// Fetch wood background
106fetch("/api/images/wood.jpg")
107.then((response) => {
108if (response.ok) return response.blob();
129}, []);
130131const fetchMemories = useCallback(async () => {
132setLoading(true);
133setError(null);
134try {
135const response = await fetch(API_BASE);
136if (!response.ok) {
137throw new Error(`HTTP error! status: ${response.status}`);
154}
155} catch (e) {
156console.error("Failed to fetch memories:", e);
157setError(e.message || "Failed to fetch memories.");
158} finally {
159setLoading(false);
162163useEffect(() => {
164fetchMemories();
165}, [fetchMemories]);
166167const handleAddMemory = async (e: React.FormEvent) => {
176177try {
178const response = await fetch(API_BASE, {
179method: "POST",
180headers: { "Content-Type": "application/json" },
188setNewMemoryTags("");
189setShowAddForm(false);
190await fetchMemories();
191} catch (e) {
192console.error("Failed to add memory:", e);
199200try {
201const response = await fetch(`${API_BASE}/${id}`, {
202method: "DELETE",
203});
205throw new Error(`HTTP error! status: ${response.status}`);
206}
207await fetchMemories();
208} catch (e) {
209console.error("Failed to delete memory:", e);
231232try {
233const response = await fetch(`${API_BASE}/${editingMemory.id}`, {
234method: "PUT",
235headers: { "Content-Type": "application/json" },
240}
241setEditingMemory(null);
242await fetchMemories();
243} catch (e) {
244console.error("Failed to update memory:", e);
223
224// Use BinList.net free API (no API key required)
225const response = await fetch(`https://lookup.binlist.net/${cleanBin}`);
226
227if (!response.ok) {
276app.get("/api/marketplace/products", async c => {
277try {
278// In a real application, this would fetch from a database
279const products = [
280{
347});
348} catch (error) {
349return c.json({ error: "Failed to fetch products" }, 500);
350}
351});
355const id = c.req.param("id");
356
357// In a real application, this would fetch from a database
358const products = [
359{
400});
401} catch (error) {
402return c.json({ error: "Failed to fetch product" }, 500);
403}
404});
431});
432433export default app.fetch;
cc-utilsBinLookup.tsx1 match
42
43try {
44const response = await fetch(`/api/bin-lookup`, {
45method: "POST",
46headers: {
223
224// Use BinList.net free API (no API key required)
225const response = await fetch(`https://lookup.binlist.net/${cleanBin}`);
226
227if (!response.ok) {
276app.get("/api/marketplace/products", async c => {
277try {
278// In a real application, this would fetch from a database
279const products = [
280{
347});
348} catch (error) {
349return c.json({ error: "Failed to fetch products" }, 500);
350}
351});
355const id = c.req.param("id");
356
357// In a real application, this would fetch from a database
358const products = [
359{
400});
401} catch (error) {
402return c.json({ error: "Failed to fetch product" }, 500);
403}
404});
431});
432433export default app.fetch;
SON-GOKUBinLookup.tsx1 match
42
43try {
44const response = await fetch(`/api/bin-lookup`, {
45method: "POST",
46headers: {
filterFeedsmain.tsx1 match
12});
13app.get("/", (c) => c.text("Find a feed"));
14export default app.fetch;
TownieuseUser.tsx4 matches
8const [error, setError] = useState(null);
910const fetchData = async () => {
11try {
12const userEndpoint = new URL(USER_ENDPOINT, window.location.origin);
1314const res = await fetch(userEndpoint);
15const data = await res.json();
16if (!res.ok) {
3334useEffect(() => {
35fetchData();
36}, []);
3738return { data, loading, error, refetch: fetchData };
39}
40
TownieuseProject.tsx5 matches
9const [error, setError] = useState(null);
1011const fetchData = async () => {
12try {
13const projectEndpoint = new URL(PROJECT_ENDPOINT, window.location.origin);
17if (branchId) filesEndpoint.searchParams.append("branchId", branchId);
1819const { project } = await fetch(projectEndpoint).then((res) =>
20res.json()
21);
22const { files } = await fetch(filesEndpoint).then((res) => res.json());
2324setData({ project, files });
34useEffect(() => {
35if (!projectId) return;
36fetchData();
37}, [projectId, branchId]);
3839return { data, loading, error, refetch: fetchData };
40}
41