142 setIsLoading(true);
143 try {
144 const response = await fetch('/api/submit-url', {
145 method: 'POST',
146 headers: {
162 const loadUrlDatabase = async () => {
163 try {
164 const response = await fetch('/api/load-urls');
165 if (!response.ok) throw new Error('Failed to load URLs');
166 const loadedUrls = await response.json();
256
257async function server(request: Request): Promise<Response> {
258 if (request.method === 'POST' && new URL(request.url).pathname === '/api/submit-url') {
259 return handleSubmitUrl(request);
260 }
261
262 if (request.method === 'GET' && new URL(request.url).pathname === '/api/load-urls') {
263 return handleLoadUrls();
264 }
63 const fetchStories = async () => {
64 try {
65 const response = await fetch("/api/stories");
66 if (!response.ok) throw new Error("Failed to fetch dates");
67 const data = await response.json();
77 try {
78 dispatch({ type: "loading", value: true });
79 const response = await fetch(`/api/comments?query=${encodeURIComponent(query)}&story=${story}&page=${page}`);
80 if (!response.ok) throw new Error("Failed to fetch comments");
81 const data = await response.json();
360export default async function(req: Request): Promise<Response> {
361 const url = new URL(req.url);
362 if (url.pathname === "/api/stories") {
363 const storySearch = await hnSearch({
364 search_by_date: true,
381 }
382
383 if (url.pathname === "/api/comments") {
384 const params = url.searchParams;
385 const query = params.get("query") || "";
4import { appendTrailingSlash } from "npm:hono/trailing-slash";
5
6// import { getVals, getValsWithVersions } from "./api.js";
7import { getVals, getValsWithVersions } from "https://esm.town/v/yawnxyz/valVersions";
8
1import { fetch } from "https://esm.town/v/std/fetch";
2import { resyPublicAPIKey } from "https://esm.town/v/vtdocs/resyPublicAPIKey";
3
4export const resyGetMatchingSlot = async (
23 const endTime = new Date(`${day} ${end}`);
24 const slotsRes = await fetch(
25 `https://api.resy.com/4/find?lat=0&long=0&day=${day}&party_size=${partySize}&venue_id=${venueId}`,
26 {
27 "headers": {
28 "authorization":
29 `ResyAPI api_key="${resyPublicAPIKey}"`,
30 "x-resy-auth-token": token,
31 },
1import { fetch } from "https://esm.town/v/std/fetch";
2import { resyPublicAPIKey } from "https://esm.town/v/vtdocs/resyPublicAPIKey";
3
4export const resyAuth = async (email: string, password: string): Promise<{
9 }[];
10}> => {
11 const authRes = await fetch("https://api.resy.com/3/auth/password", {
12 "headers": {
13 "authorization": `ResyAPI api_key="${resyPublicAPIKey}"`,
14 "content-type": "application/x-www-form-urlencoded",
15 "User-Agent":
30 try {
31 const r = await fetch(
32 "https://fonts.googleapis.com/css2?family=" +
33 encodeURIComponent("IBM Plex Sans:wght@600") +
34 "&text=" +
16const app = new Hono();
17
18const vapidDetails = {
19 url: thisWebURL(),
20 pubKey: Deno.env.get("qushVapidPublicKey"),
21 privKey: Deno.env.get("qushVapidPrivateKey"),
22};
23
57});
58
59app.get("/vapidPublicKey", (c) => c.text(vapidDetails.pubKey));
60
61app.get("/", async (c) => {
103 await storage.set(subscription);
104 if (subscription !== null) {
105 await pushSendNotification(vapidDetails, subscription, "👋");
106 return c.text("Subscribed!");
107 }
112 const subscription = await storage.get();
113 if (subscription === null) return false;
114 await pushSendNotification(vapidDetails, subscription, ...params);
115 return true;
116};
1/**
2 * This val creates a Postman-like interface for testing HTTP requests directly in the browser.
3 * It uses React for the UI and the Fetch API to make requests.
4 * The server function serves the HTML and handles the API requests.
5 */
6
1/**
2 * This is a minimalist to-do list app using server-side rendering without any client-side JavaScript.
3 * It uses Val Town's SQLite for data persistence, Deno's standard library for HTML escaping,
4 * and custom SVG icons for a cohesive design.
5 */
84 <meta name="viewport" content="width=device-width, initial-scale=1.0">
85 <title>To Do List</title>
86 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700&display=swap" rel="stylesheet">
87 <style>
88 body {
54You can attach files to your emails by using the `attachments` field.
55Attachments need to be [Base64](https://en.wikipedia.org/wiki/Base64) encoded,
56which is that the [btoa](https://developer.mozilla.org/en-US/docs/Web/API/btoa)
57method is doing in this example:
58