3// we can make it interactive with additional scripts.
45export default async function(req: Request): Promise<Response> {
6const url = new URL(req.url);
7const pathname = url.pathname;
57}
5859function renderStoryPage(storyId: string): string {
60const stories = {
61"1": {
tomatoSawfishmain.tsx1 match
2import { render } from "npm:preact-render-to-string";
34export default async function(req: Request) {
5return new Response(
6render(
valPreviewmain.tsx9 matches
1export async function fetchVal(valId: string) {
2try {
3const response = await fetch(`https://api.val.town/v1/vals/${valId}`);
13}
1415export async function evalCode(code: string) {
16try {
17const response = await fetch(`https://api.val.town/v1/eval`, {
46}
4748function handleEvalCode(elementId: string) {
49const element = document.getElementById(`code-${elementId}`);
50if (element) {
73}
7475export async function previewVal(valName: string, resultElementId: string) {
76try {
77const resultElement = document.getElementById(resultElementId);
94}
9596function escapeHtml(unsafe: string) {
97return unsafe
98.replace(/&/g, "&")
103}
104105export function injectValContent(valId: string, elementId: string) {
106return fetchVal(valId).then(data => {
107if (data) {
225}
226227export function initializeValComponents() {
228document.querySelectorAll('[data-val-id]').forEach(element => {
229const valId = element.getAttribute('data-val-id');
237}
238239function handlePreviewVal(elementId: string, valName: string) {
240const previewElementId = `preview-${elementId}`;
241previewVal(valName, previewElementId).catch(error => {
248}
249250// Ensure the handler functions are accessible globally
251(window as any).handlePreviewVal = handlePreviewVal;
252(window as any).handleEvalCode = handleEvalCode;
1// This val responds to HTTP requests with "Hello world"
2export default async function main(req: Request): Promise<Response> {
3return new Response("Hello world");
4}
1// This val will respond to all HTTP requests with "Hello world"
23export default async function(req: Request): Promise<Response> {
4return new Response("Hello world", {
5headers: { "Content-Type": "text/plain" },
1// This val simply responds to all HTTP requests with "Hello world"
2export default async function main(req: Request): Promise<Response> {
3return new Response("Hello world");
4}
1// This val will respond with "Hello, World!" to all incoming HTTP requests.
23export default async function main(req: Request): Promise<Response> {
4return new Response("Hello, World!", { headers: { "Content-Type": "text/plain" } });
5}
1// This val will respond with "Hello world" to all incoming HTTP requests
23export default async function main(req: Request): Promise<Response> {
4return new Response("Hello world");
5}
2// It uses Deno's built-in HTTP server.
34export default async function main(req: Request): Promise<Response> {
5return new Response("Hello, World!", {
6headers: { "Content-Type": "text/plain" },
1// This val responds with "Hello, World!"
2export default async function main(req: Request): Promise<Response> {
3return new Response("Hello, World!", {
4headers: {