Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Readme

Usage

  1. Create proxy val for your turso DB (make it private to protect it behind your val town token)
import {createTursoProxy} from "https://esm.town/v/pomdtr/createTursoProxy" export default createTursoProxy("<tursoDatabaseUrl>", "<tursoAuthToken>")
  1. Wire any existing val to the proxy val
import { setEnv } from "https://esm.town/v/pomdtr/setEnv"; // use my private proxy setEnv("VALTOWN_API_URL", "<proxy-url>"); // wire sqlite explorer to a turso db ! const { handler } = await import("https://esm.town/v/nbbaier/sqliteExplorerApp"); export default handler;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Hono } from "jsr:@hono/hono";
import { createClient } from "npm:@libsql/client";
export function createTursoProxy(databaseUrl: string, authToken: string) {
const client = createClient({
url: `${databaseUrl}?authToken=${Deno.env.get("TURSO_AUTH_TOKEN")}`,
});
const app = new Hono();
app.post("/v1/sqlite/batch", async (c) => {
const { statements, mode } = await c.req.json();
if (!statements) {
return new Response("No statements", { status: 400 });
}
const res = await client.batch(statements, mode);
return new Response(JSON.stringify(res));
});
app.post("/v1/sqlite/execute", async (c) => {
const { statement } = await c.req.json();
if (!statement) {
return new Response("No statement", { status: 400 });
}
const res = await client.execute(statement);
return new Response(JSON.stringify(res));
});
app.all("*", async (c) => {
const { path } = c.req;
return await fetch(`https://api.val.town${path}`, {
method: c.req.method,
headers: c.req.raw.headers,
body: c.req.raw.body,
});
});
return app.fetch;
}
June 9, 2024