cardamomval-town.mdc3 matches
221222// Inject data to avoid extra round-trips
223const initialData = await fetchInitialData();
224const dataScript = `<script>
225window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
2682695. **API Design:**
270- `fetch` handler is the entry point for HTTP vals
271- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
2722736. **Hono Peculiarities:**
proxydatasaver.ts11 matches
44}
4546interface FetchResult {
47html: string;
48contentLength: number;
50}
5152async function fetchContent(
53url: string,
54reqHeaders: Headers,
55): Promise<FetchResult | null> {
56console.log(`Fetching URL: ${url}`);
5758// Copy certain headers from the original request
66// });
6768// Add Accept-Encoding header to request common compression types supported by fetch()
69headers["accept-encoding"] = "gzip, deflate, br";
7071console.debug(`DEBUG: -> Request headers:`, headers);
7273const response = await fetch(url, { headers });
74console.debug(`DEBUG: -> Status: ${response.status}`);
7576if (!response.ok) {
77console.error(
78`Failed to fetch ${url}: ${response.status} ${response.statusText}`,
79);
80return null;
596597try {
598const fetchResult = await fetchContent(targetUrl, req.headers);
599if (!fetchResult) {
600return new Response("Failed to fetch content", { status: 502 });
601}
602603const { html, contentLength, compression } = fetchResult;
604605let processingMode = determineProcessingMode(req.url, targetUrl, html);
qkwnew02_http.tsx1 match
11forwardedHeaders.delete("host");
1213const res = await fetch(targetUrl, {
14method: req.method,
15headers: forwardedHeaders,
362
363try {
364// Fetch the source code
365const response = await fetch(sourceUrl);
366if (!response.ok) {
367return c.text(`Failed to fetch source: ${response.status}`, 404);
368}
369
611async function detectBlock(code, line, column) {
612if (blockDetectorUrl) {
613const response = await fetch(blockDetectorUrl, {
614method: 'POST',
615headers: { 'Content-Type': 'application/json' },
624async function explainBlock(code, blockInfo) {
625if (blockExplainerUrl) {
626const response = await fetch(blockExplainerUrl, {
627method: 'POST',
628headers: { 'Content-Type': 'application/json' },
770}
771772export default app.fetch;
39```
4041This will fetch the source from `https://esm.town/v/nbbaier/sqliteExplorerApp@100-main/main.tsx` and display it with annotations.
4243### Custom Functions
1361371. **URL Parsing**: Extracts the val path from the URL
1382. **Source Fetching**: Fetches source code from `https://esm.town/v/{path}`
1393. **Language Detection**: Determines language from file extension
1404. **Syntax Highlighting**: Applies syntax highlighting using Prism.js
155## Error Handling
156157- Returns 404 if the source URL cannot be fetched
158- Returns 400 for invalid path formats
159- Returns 500 for other errors with error messages
reactHonoStarterApp.tsx2 matches
82const mutation = useMutation({
83mutationFn: async () => {
84const res = await fetch("/api/random-dewey");
85if (!res.ok) {
86throw new Error(
87"Failed to fetch random numbers. The quantum source might be temporarily unavailable."
88);
89}
blob_adminmain.tsx1 match
199});
200201export default lastlogin((request: Request) => app.fetch(request));
blob_adminapp.tsx22 matches
231const [isDragging, setIsDragging] = useState(false);
232233const fetchBlobs = useCallback(async () => {
234setLoading(true);
235try {
236const response = await fetch(`/api/blobs?prefix=${encodeKey(searchPrefix)}&limit=${limit}`);
237const data = await response.json();
238setBlobs(data);
239} catch (error) {
240console.error("Error fetching blobs:", error);
241} finally {
242setLoading(false);
245246useEffect(() => {
247fetchBlobs();
248}, [fetchBlobs]);
249250const handleSearch = (e) => {
261setBlobContentLoading(true);
262try {
263const response = await fetch(`/api/blob?key=${encodeKey(clickedBlob.key)}`);
264const content = await response.text();
265setSelectedBlob({ ...clickedBlob, key: decodeKey(clickedBlob.key) });
266setEditContent(content);
267} catch (error) {
268console.error("Error fetching blob content:", error);
269} finally {
270setBlobContentLoading(false);
275const handleSave = async () => {
276try {
277await fetch(`/api/blob?key=${encodeKey(selectedBlob.key)}`, {
278method: "PUT",
279body: editContent,
287const handleDelete = async (key) => {
288try {
289await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
290setBlobs(blobs.filter(b => b.key !== key));
291if (selectedBlob && selectedBlob.key === key) {
304const key = `${searchPrefix}${file.name}`;
305formData.append("key", encodeKey(key));
306await fetch("/api/blob", { method: "POST", body: formData });
307const newBlob = { key, size: file.size, lastModified: new Date().toISOString() };
308setBlobs([newBlob, ...blobs]);
312}
313}
314fetchBlobs();
315};
316326try {
327const fullKey = `${searchPrefix}${key}`;
328await fetch(`/api/blob?key=${encodeKey(fullKey)}`, {
329method: "PUT",
330body: "",
341const handleDownload = async (key) => {
342try {
343const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
344const blob = await response.blob();
345const url = window.URL.createObjectURL(blob);
360if (newKey && newKey !== oldKey) {
361try {
362const response = await fetch(`/api/blob?key=${encodeKey(oldKey)}`);
363const content = await response.blob();
364await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
365method: "PUT",
366body: content,
367});
368await fetch(`/api/blob?key=${encodeKey(oldKey)}`, { method: "DELETE" });
369setBlobs(blobs.map(b => b.key === oldKey ? { ...b, key: newKey } : b));
370if (selectedBlob && selectedBlob.key === oldKey) {
380const newKey = `__public/${key}`;
381try {
382const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
383const content = await response.blob();
384await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
385method: "PUT",
386body: content,
387});
388await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
389setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
390if (selectedBlob && selectedBlob.key === key) {
399const newKey = key.slice(9); // Remove "__public/" prefix
400try {
401const response = await fetch(`/api/blob?key=${encodeKey(key)}`);
402const content = await response.blob();
403await fetch(`/api/blob?key=${encodeKey(newKey)}`, {
404method: "PUT",
405body: content,
406});
407await fetch(`/api/blob?key=${encodeKey(key)}`, { method: "DELETE" });
408setBlobs(blobs.map(b => b.key === key ? { ...b, key: newKey } : b));
409if (selectedBlob && selectedBlob.key === key) {
1export async function urlGetter(sourceURl) {
2// convert object to array containing arrays with key value pairs. use map to iterate over the values then convert arrays to objects
3const response = await fetch(sourceURl);
4const html = await response.text();
5const matches = [...html.matchAll(/<a[^>]*href="([^"]+)"[^>]*>(.*?)<\/a>/g)].map((match) => match[1]);
reactHonoStarterindex.ts1 match
37});
3839export default app.fetch; // This is the entry point for HTTP vals
40