13## Authentication
14
15Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
16
17## Todos / Plans
27 <head>
28 <title>SQLite Explorer</title>
29 <link rel="preconnect" href="https://fonts.googleapis.com" />
30
31 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32 <link
33 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34 rel="stylesheet"
35 />
1import { createClient, type NormalizeOAS } from "npm:fets@0.8.3";
2import type openapi from "npm:smallweb@0.14.4";
3
4if (!Deno.env.get("SMALLWEB_API_URL")) {
5 throw new Error("Missing SMALLWEB_API_URL");
6}
7
8if (!Deno.env.get("SMALLWEB_API_TOKEN")) {
9 throw new Error("Missing SMALLWEB_API_TOKEN");
10}
11
12export const smallweb = createClient<NormalizeOAS<typeof openapi>>({
13 endpoint: Deno.env.get("SMALLWEB_API_URL"),
14 globalParams: {
15 headers: { Authorization: `Bearer ${Deno.env.get("SMALLWEB_API_TOKEN")}` },
16 },
17});
244 const { code, name } = await request.json();
245
246 // Create a new val using the Val Town API
247 const response = await fetch("https://api.val.town/v1/vals", {
248 method: "POST",
249 headers: {
250 "Content-Type": "application/json",
251 "Authorization": `Bearer ${Deno.env.get("VAL_TOWN_API_KEY")}`,
252 },
253 body: JSON.stringify({
290
291const css = `
292@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
293
294body {
244 const { code, name } = await request.json();
245
246 // Create a new val using the Val Town API
247 const response = await fetch("https://api.val.town/v1/vals", {
248 method: "POST",
249 headers: {
250 "Content-Type": "application/json",
251 "Authorization": `Bearer ${Deno.env.get("VAL_TOWN_API_KEY")}`,
252 },
253 body: JSON.stringify({
290
291const css = `
292@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap');
293
294body {
8
91. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
8
91. Click `Fork`
102. Change `location` (Line 4) to describe your location. It accepts fairly flexible English descriptions which it turns into locations via [nominatim's geocoder API](https://www.val.town/v/stevekrouse/nominatimSearch).
113. Click `Run`
12
14const app = new Hono();
15
16// key format is same as web-push's generateVAPIDKeys
17const vapidDetails = {
18 url: thisWebURL(),
19 pubKey: Deno.env.get("pushVapidPublicKey"),
20 privKey: Deno.env.get("pushVapidPrivateKey"),
21};
22
23if (vapidDetails.privKey === undefined || vapidDetails.pubKey === undefined) {
24 throw new Error("You must set pubKey and privKey secrets!");
25}
60});
61
62app.get("/vapidPublicKey", (c) => c.text(vapidDetails.pubKey));
63
64app.get("/", async (c) => {
106 await storage.set(subscription);
107 if (subscription !== null) {
108 await pushSendNotification(vapidDetails, subscription, "👋");
109 return c.text("Subscribed!");
110 }
115 const subscription = await storage.get();
116 if (subscription === null) return false;
117 await pushSendNotification(vapidDetails, subscription, ...params);
118 return true;
119};
27 <head>
28 <title>SQLite Explorer</title>
29 <link rel="preconnect" href="https://fonts.googleapis.com" />
30
31 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
32 <link
33 href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@300..700&family=Source+Sans+3:ital,wght@0,200..900;1,200..900&display=swap"
34 rel="stylesheet"
35 />
13## Authentication
14
15Login to your SQLite Explorer with [password authentication](https://www.val.town/v/pomdtr/password_auth) with your [Val Town API Token](https://www.val.town/settings/api) as the password.
16
17## Todos / Plans