24 const [errorMessage, setErrorMessage] = useState<string>("");
25
26 const fetchRandomVerse = async () => {
27 setStatus("loading");
28 setErrorMessage("");
46 : endpoint.url;
47
48 const response = await fetch(url, {
49 mode: "cors", // Enable CORS
50 headers: {
76 setStatus("error");
77 setErrorMessage(
78 `Failed to fetch verse after ${maxAttempts} attempts. ${
79 error instanceof Error ? error.message : "Unknown error"
80 }. Please try again later.`,
85 };
86
87 // Auto-fetch verse on component mount
88 useEffect(() => {
89 fetchRandomVerse();
90 }, []);
91
217 </div>
218 <button
219 onClick={fetchRandomVerse}
220 disabled={status === "loading"}
221 style={{
261
262 try {
263 const response = await fetch("https://bible-api.com/?random=true&translation=asv");
264 const data = await response.json();
265
77 const geocodeLocation = async (query: string) => {
78 try {
79 const response = await fetch(
80 `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}`
81 );
107 if (coordinates) {
108 setLocation(coordinates);
109 await fetchRecommendations(coordinates.latitude, coordinates.longitude);
110
111 // Scroll to map
114 };
115
116 // Modify fetchRecommendations to calculate distances
117 const fetchRecommendations = async (latitude: number, longitude: number) => {
118 setLoading(true);
119 setError(null);
121
122 try {
123 const response = await fetch('/recommendations', {
124 method: 'POST',
125 body: JSON.stringify({ latitude, longitude })
127
128 if (!response.ok) {
129 throw new Error('Failed to fetch recommendations');
130 }
131
231 const { lat, lng } = e.latlng;
232 setLocation({ latitude: lat, longitude: lng });
233 fetchRecommendations(lat, lng);
234 });
235 }
245 const { latitude, longitude } = position.coords;
246 setLocation({ latitude, longitude });
247 await fetchRecommendations(latitude, longitude);
248 },
249 (positionError) => {
328 </h2>
329 {loading ? (
330 <p>Fetching local recommendations...</p>
331 ) : recommendations.length === 0 ? (
332 <p>Click on the map or search for a location to get recommendations</p>
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
2
3export default async function(req: Request): Promise<Response> {
4 const markdown = await fetch(import.meta.resolve("./README.md")).then(res => res.text());
5 const url = new URL(req.url);
6
140});
141
142export default app.fetch;
140});
141
142export default app.fetch;
2export async function importFile(path: string) {
3 const url = new URL(path, import.meta.url);
4 const res = await fetch(url, { redirect: "follow" });
5 if (!res.ok) return null;
6 return await res.text();
20
21 try {
22 const response = await fetch("/chat", {
23 method: "POST",
24 headers: { "Content-Type": "application/json" },
57
58 useEffect(() => {
59 fetchState();
60 }, []);
61
62 /**
63 * Fetches the current state from the server
64 */
65 const fetchState = async () => {
66 setIsLoading(true);
67 setError(null);
68 try {
69 const response = await fetch("/api/state");
70 if (!response.ok) throw new Error("Failed to fetch state");
71 const data = await response.json();
72 setState(data);
86 setError(null);
87 try {
88 const response = await fetch("/api/state", {
89 method: "POST",
90 headers: { "Content-Type": "application/json" },
92 });
93 if (!response.ok) throw new Error("Failed to update state");
94 await fetchState();
95 } catch (err) {
96 setError(err.message);
546 if (webhookUrl) {
547 try {
548 await fetch(webhookUrl, {
549 method: "POST",
550 headers: { "Content-Type": "application/json" },
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({