29## How It Works
30
31The visualizer fetches the project structure using Val Town's `listFiles` utility, then creates both a text representation and an interactive diagram of the file structure.
32
33## Development
6// import markdown file
7const url = new URL("content.md", import.meta.url);
8const res = await fetch(url, { redirect: "follow" });
9const markdown = await res.text();
10
232});
233
234// HTTP vals expect an exported "fetch handler"
235// This is how you "run the server" in Val Town with Hono
236export default app.fetch;
25 }
26
27 const response = await fetch(`/fork?url=${encodeURIComponent(projectUrl)}`, {
28 method: "POST",
29 headers: {
11
12 try {
13 const response = await fetch("/messages", {
14 method: "POST",
15 headers: { "Content-Type": "application/json" },
60});
61
62// HTTP vals expect an exported "fetch handler"
63// This is how you "run the server" in Val Town with Hono
64export default app.fetch;
9 const [messages, setMessages] = React.useState(initialMessages);
10
11 const fetchMessages = async () => {
12 try {
13 const response = await fetch("/messages");
14 const data = await response.json();
15 setMessages(data.reverse());
16 } catch (error) {
17 console.error("Failed to fetch messages", error);
18 }
19 };
23 <h1>💬 Message Board</h1>
24 <MessageList messages={messages} />
25 <MessageInput onSubmit={fetchMessages} />
26 {thisProjectURL
27 ? (
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);
551 if (webhookUrl) {
552 try {
553 await fetch(webhookUrl, {
554 method: "POST",
555 headers: { "Content-Type": "application/json" },
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({