Townie-05requests.ts2 matches
56row.parentNode.insertBefore(newRow, row.nextSibling);
57
58// Fetch the inference calls data
59fetch('/api/inference-calls?usage_id=' + usageId)
60.then(response => response.json())
61.then(data => {
Townie-05project-files.ts2 matches
30return c.json({ files: files.data });
31} catch (error) {
32console.error("Error fetching project files:", error);
33return Response.json({ error: "Failed to fetch project files" }, { status: 500 });
34}
35});
Townie-05project-branches.ts2 matches
21return c.json({ branches: branches.data });
22} catch (error) {
23console.error("Error fetching branches:", error);
24return Response.json({ error: "Failed to fetch branches" }, { status: 500 });
25}
26});
Townie-05.cursorrules3 matches
239
240// Inject data to avoid extra round-trips
241const initialData = await fetchInitialData();
242const dataScript = `<script>
243window.__INITIAL_DATA__ = ${JSON.stringify(initialData)};
2862875. **API Design:**
288- `fetch` handler is the entry point for HTTP vals
289- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
290291
esmTownTranspileDemo2main.tsx2 matches
1/** @jsxImportSource https://esm.sh/react */
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText";
34console.log(
5await fetchText("https://esm.town/v/jxnblk/react-importmap-starter/client.tsx", {
6headers: {
7"User-Agent": "", // can't include Deno, which on Val Town it would by default
5It doesn't do as much as other transpilers (such as esm.sh, such as rewriting `npm:` imports, etc). We may add that capability in the future. For now, if you want your npm imports to run in the browser, use `https://esm.sh/package` instead of `npm:package`.
67The below script demonstrates this transiplation behavior by fetching its own source code (`import.meta.url`) with the user agent of a browser. You can uncoment the line setting the browser agent if you want to see the difference in the output. Or you could just load this val's module URL in your browser to see the untranspiled TS.
89As of July 23, 2024, this is the code that determines when esm.town transpiles or not:
45// User-related API calls
46async createUser(userData) {
47const response = await fetch('/api/users', {
48method: 'POST',
49headers: { 'Content-Type': 'application/json' },
60
61async getUser(userId) {
62const response = await fetch(`/api/users/${userId}`);
63
64const data = await response.json();
71
72async updateUser(userId, userData) {
73const response = await fetch(`/api/users/${userId}`, {
74method: 'PATCH',
75headers: { 'Content-Type': 'application/json' },
87// Playlist-related API calls
88async getUserPlaylists(userId) {
89const response = await fetch(`/api/playlists/user/${userId}`);
90
91const data = await response.json();
104}
105
106const response = await fetch(url);
107
108const data = await response.json();
116// Session-related API calls
117async getUserSessions(userId) {
118const response = await fetch(`/api/sessions/user/${userId}`);
119
120const data = await response.json();
127
128async getSession(sessionId) {
129const response = await fetch(`/api/sessions/${sessionId}`);
130
131const data = await response.json();
139// AI recommendation API calls
140async generatePlaylist(userId, request) {
141const response = await fetch('/api/recommendations/playlist', {
142method: 'POST',
143headers: { 'Content-Type': 'application/json' },
154
155async generateDrills(userId, request) {
156const response = await fetch('/api/recommendations/drills', {
157method: 'POST',
158headers: { 'Content-Type': 'application/json' },
169
170async generateSession(userId, request) {
171const response = await fetch('/api/recommendations/session', {
172method: 'POST',
173headers: { 'Content-Type': 'application/json' },
141});
142143// HTTP vals expect an exported "fetch handler"
144// This is how you "run the server" in Val Town with Hono
145export default app.fetch;