5
6/**
7 * Fetches a URL and returns the HTML content
8 */
9export const queryUrl = tool({
15 console.log(`[QUERYING]: ${url}`);
16
17 const res = await fetch(url);
18 const html = await res.text();
19
34 console.log(`[ANALYZING]: ${url}`);
35
36 const response = await fetch(url);
37 const html = await response.text();
38
61 console.log(`[EXTRACTING SECTION]: ${sectionId} from ${url}`);
62
63 const response = await fetch(url);
64 const html = await response.text();
65
97 console.log(`[DISCOVERING LINKS]: ${url}`);
98
99 const response = await fetch(url);
100 const html = await response.text();
101
154 console.log(`[ANALYZING PATTERNS]: ${selector} for ${url}`);
155
156 const response = await fetch(url);
157 const html = await response.text();
158
65// deno-lint-ignore require-await
66export default async function server(request: Request): Promise<Response> {
67 return app.fetch(request);
68}
69
10 const refineText = async () => {
11 setLoading(true);
12 const res = await fetch("/refine", {
13 method: "POST",
14 headers: { "Content-Type": "application/json" },
20 };
21
22 const fetchLogs = async () => {
23 const res = await fetch("/logs");
24 const data = await res.json();
25 setLogs(data);
27
28 useEffect(() => {
29 fetchLogs();
30 }, []);
31
33});
34
35// HTTP vals expect an exported "fetch handler"
36// This is how you "run the server" in Val Town with Hono
37export default app.fetch;
38
24 if (url.pathname !== "/") {
25 const githubPagesUrl = `https://stevekrouse.github.io${url.pathname}${url.search}`;
26 const response = await fetch(
27 new Request(githubPagesUrl, {
28 method: request.method,
10async function persistLogs(logs: LogEntry[]) {
11 try {
12 const existingLogs = await fetch(logFileName)
13 .then(response => response.json())
14 .catch(() => []);
15 const updatedLogs = [...existingLogs, ...logs];
16 await fetch(logFileName, {
17 method: "PUT",
18 body: JSON.stringify(updatedLogs),
17 const [error, setError] = useState<string | null>(null);
18
19 // Fetch todos from the API
20 const fetchTodos = async () => {
21 try {
22 setIsLoading(true);
23 setError(null);
24 const response = await fetch(`${getApiBaseUrl()}/api/todos`);
25 if (!response.ok) {
26 throw new Error("Failed to fetch todos");
27 }
28 const data = await response.json();
44 setIsLoading(true);
45 setError(null);
46 const response = await fetch(`${getApiBaseUrl()}/api/todos`, {
47 method: "POST",
48 headers: {
78 );
79
80 const response = await fetch(`${getApiBaseUrl()}/api/todos/${id}`, {
81 method: "PATCH",
82 headers: {
114 setTodos(todos.filter((todo) => todo.id !== id));
115
116 const response = await fetch(`${getApiBaseUrl()}/api/todos/${id}`, {
117 method: "DELETE",
118 });
123 } catch (err) {
124 // Revert the optimistic update on error
125 fetchTodos();
126 setError("Failed to delete todo. Please try again.");
127 console.error(err);
5async function servePublicFile(path: string): Promise<Response> {
6 const url = new URL("./public/" + path, import.meta.url);
7 const text = await (await fetch(url, {
8 headers: {
9 "User-Agent": "", // to transpile TS to JS
181
182 try {
183 const response = await fetch("/", {
184 method: "POST",
185 body: JSON.stringify({
12
13- `/push` will copy the contents from a list of vals specified in `config.json` and push them to a GitHub repo
14- `/deploy` is a GitHub webhook URL that will fetch contents from GitHub and update the code on Val Town
15
161. Fork this val
271. Add a `VAL_SECRET` env var to the val. Use this secret to sign the webhook POST request to the `/push` endpoint. Use this endpoint to commit vals from Val Town to your GitHub repo.
28
29### Example push to GitHub fetch
30
31You can use this example to POST to the `/push` endpoint to copy vals to GitHub.
46 const signature = await sign(body, secret);
47
48 const res = await fetch(url, {
49 method: "POST",
50 body,
89- [x] Monkey test
90- [x] Add setup instructions to readme
91- [x] Add example code for private webhook fetch
92- [x] Make val and repo public
93- [ ] Check modified date before export to GitHub??