2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
1export default async function(req) {
2 return new Response(
3 `<!DOCTYPE html>
125 });
126
127 function draw() {
128 ctx.clearRect(0, 0, canvasSize, canvasSize);
129
139 }
140
141 function update() {
142 const head = { x: snake[0].x + direction.x, y: snake[0].y + direction.y };
143 snake.unshift(head);
168 }
169
170 function resetGame() {
171 clearInterval(gameInterval);
172 snake = [{ x: 5, y: 5 }];
181 }
182
183 function startGame() {
184 document.querySelector('.start-button').style.display = 'none';
185 resetGame();
186 }
187
188 function changeDirection(event) {
189 switch (event.code) {
190 case 'ArrowUp':
6
7// Fetches a random joke.
8async function fetchRandomJoke() {
9 const response = await fetch(
10 "https://official-joke-api.appspot.com/random_joke",
2import { useState } from "https://esm.sh/react@18.2.0";
3
4export function App() {
5 const [clicked, setClicked] = useState(0);
6 return (
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
2
3// Fetches a random joke.
4async function fetchRandomJoke() {
5 const response = await fetch(
6 "https://official-joke-api.appspot.com/random_joke",
1export default async function (req: Request): Promise<Response> {
2 return Response.json({ ok: true })
3}
122We didn't. We left them where they are, and proxy to them.
123
124Writing a proxy in Val Town (or any functions platform with the ['fetch handler' interface](https://blog.val.town/blog/the-api-we-forgot-to-name/)) is always a delight:
125
126```ts
127const OLD_BLOG_HOST = "https://val-town-blog.pages.dev/";
128export async function proxy(req: Request): Promise<Response> {
129 const url = new URL(req.url);
130 return fetch(OLD_BLOG_HOST + url.pathname + url.search, {
1export function formatDate(dateString: string): string {
2 try {
3 const date = new Date(dateString);
12}
13
14export function dayOfWeek(dateString: string): string {
15 try {
16 return new Date(dateString).toLocaleDateString("en-US", {
2import { BlueskyIcon, DiscordIcon, GitHubIcon, RSSIcon, TwitterIcon } from "./icons.tsx";
3
4export default function SocialLinks() {
5 return (
6 <div className="social-links">
A helper function to build a file's email
Simple functional CSS library for Val Town
LangChain (https://langchain.com) Ambassador, KubeSphere (https://kubesphere.io) Ambassador, CNCF OpenFunction (https://openfunction.dev) TOC Member.
import { OpenAI } from "https://esm.town/v/std/openai";
export default async function(req: Request): Promise<Response> {
if (req.method === "OPTIONS") {
return new Response(null, {
headers: {
"Access-Control-Allow-Origin": "*",