5
6const app = new Hono();
7export default app.fetch;
8app.get("/", async (c) => {
9 const description = c.req.query("description") || "On weekdays at noon";
1import { API_URL } from "https://esm.town/v/std/API_URL?v=5";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=42";
3import { Octokit } from "npm:@octokit/rest";
4import { DateTime } from "npm:luxon";
127
128 try {
129 const { code } = await fetchJSON(`${API_URL}/v1/alias/${vtUser}/${valName}`, {
130 headers: { "Authorization": `Bearer ${Deno.env.get("valtown")}` },
131 });
1export const newClient = async (username: string, password: string): Client => {
2 const url = `https://${username}-userspaceauth.web.val.run/validate/${password}`;
3 let resp = await fetch(url);
4 if (resp.status !== 200) {
5 throw new Error("Invliad response. Have you set up your fork? https://www.val.town/v/maxm/userspaceauth/fork?");
99 return c.json(match, match ? 200 : 401);
100});
101export default app.fetch;
102
103// console.log(await opaque.getOpaqueConfig(opaque.OpaqueID.OPAQUE_P521).ake.generateAuthKeyPair());
1import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON?v=41";
2
3export const slackReplyToMessage = async (req: Request) => {
15 // Note: `body.event` has information about the event
16 // like the sender and the message text
17 const result = await fetchJSON(
18 "https://slack.com/api/chat.postMessage",
19 {
21});
22
23export default router.fetch;
1import { resetStyle } from "https://esm.town/v/nbbaier/resetStyle";
2import { fetchText } from "https://esm.town/v/stevekrouse/fetchText?v=6";
3import { html } from "https://esm.town/v/stevekrouse/html?v=5";
4import { Readability } from "npm:@mozilla/readability";
89 }
90
91 let body = await fetchText(articleUrl);
92
93 let doc = new JSDOM(body);
1import { sqlite } from "https://esm.town/v/std/sqlite?v=4";
2import { fetchJSON } from "https://esm.town/v/stevekrouse/fetchJSON";
3import { getDocs } from "https://esm.town/v/stevekrouse/getSqliteDateMeDocs";
4import { thisWebURL } from "https://esm.town/v/stevekrouse/thisWebURL";
36export async function setupDatabase() {
37 await createTable();
38 const docs = await fetchJSON(thisWebURL());
39 return docs.map(args =>
40 sqlite.execute({
1# Reload in new tabs when your vals change
2
3When you're working on an HTML HTTP val in a new tab, it's annoying to have to manually reload the tab on every save. In the Val Town editor, you can hit cmd+enter, but there's nothing like that for a val in a new tab because Val Town doesn't control that new tab (like we control the iframe in the browser preview). However, you control that HTML via the fetch handler you're writing, so you can add a script that polls the Val Town API for the current version number of your val, and reload itself if it detects a new version. This val has a collection of helpers to help you do just that.
4
5## Usage
7```ts
8import { html } from "https://esm.town/v/stevekrouse/html";
9import { reloadOnSaveFetchMiddleware } from "https://esm.town/v/stevekrouse/reloadOnSave";
10
11export default reloadOnSaveFetchMiddleware(async function(req: Request): Promise<Response> {
12 return html(`<h1>Hello!!</h1>`);
13})
1import { fetchRSS } from "https://esm.town/v/stevekrouse/fetchRSS";
2
3export let newRSSItems = ({ url, lastRunAt }) =>
4 fetchRSS(url)
5 .then(({ channel: { item } }) =>
6 (Array.isArray(item) ? item : [item]).filter(