3// Initialize Notion client
4const notion = new Client({
5 auth: Deno.env.get("NOTION_API_KEY"),
6});
7
3// Initialize Notion client
4const notion = new Client({
5 auth: Deno.env.get("NOTION_API_KEY"),
6});
7
21import * as Main from "chrome-devtools-frontend/entrypoints/main/main.js";
22
23// Fix crash on Firefox (non standard / unsupported api used)
24ShadowRoot.prototype.getSelection = ShadowRoot.prototype.getComponentSelection;
25Element.prototype.scrollIntoViewIfNeeded = Element.prototype.scrollIntoView;
49 const teamId = "5LJ2HBVN6V";
50 const bundleId = isStaging ? "com.oneroofapp.snag.dev.voip" : "com.oneroofapp.snag.voip";
51 const endpoint = isSandbox ? "https://api.sandbox.push.apple.com/3/device" : "https://api.push.apple.com/3/device";
52
53 // 2. Create the JWT for authentication.
52 const apnsResponse = await fetch(
53 // The APNs endpoint includes the target device token.
54 `https://api.push.apple.com/3/device/${deviceToken}`,
55 {
56 method: "POST",
6 <title>React Hono Val Town Starter</title>
7 <script src="https://cdn.tailwindcss.com"></script>
8 <link rel="preconnect" href="https://fonts.googleapis.com">
9 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
10 <link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&display=swap" rel="stylesheet">
11 <link rel="icon" href="/public/favicon.svg" sizes="any" type="image/svg+xml">
12 <style>
38```
39
40## API Endpoints
41
42- `GET /` - Serves the React application with initial data
43- `GET /api/messages` - Fetch all messages (JSON)
44- `POST /api/messages` - Create a new message
45- `GET /public/**` - Static assets (CSS, JS, etc.)
46- `/*` - All other routes handled by TanStack Router
8## Hono
9
10This app uses [Hono](https://hono.dev/) as the API framework. You can think of Hono as a replacement for [ExpressJS](https://expressjs.com/) that works in serverless environments like Val Town or Cloudflare Workers. If you come from Python or Ruby, Hono is also a lot like [Flask](https://github.com/pallets/flask) or [Sinatra](https://github.com/sinatra/sinatra), respectively.
11
12## Serving assets to the frontend
20### `index.html`
21
22The most complicated part of this backend API is serving index.html. In this app (like most apps) we serve it at the root, ie `GET /`.
23
24We *bootstrap* `index.html` with some initial data from the server, so that it gets dynamically injected JSON data without having to make another round-trip request to the server to get that data on the frontend. This is a common pattern for client-side rendered apps.
25
26## CRUD API Routes
27
28This app has two CRUD API routes: for reading and inserting into the messages table. They both speak JSON, which is standard. They import their functions from `/backend/database/queries.ts`. These routes are called from the React app to refresh and update data.
29
30## Errors
31
32Hono and other API frameworks have a habit of swallowing up Errors. We turn off this default behavior by re-throwing errors, because we think most of the time you'll want to see the full stack trace instead of merely "Internal Server Error". You can customize how you want errors to appear.
7 queryKey: ["messages"],
8 queryFn: async () => {
9 const response = await fetch("/api/messages");
10 if (!response.ok) {
11 throw new Error("Failed to fetch messages");
25 return useMutation({
26 mutationFn: async (content: string) => {
27 const response = await fetch("/api/messages", {
28 method: "POST",
29 headers: { "Content-Type": "application/json" },
34app.get("/shared/**/*", c => serveFile(c.req.path, import.meta.url));
35
36// API endpoints
37app.get("/api/messages", async (c) => {
38 const messages = await getMessages();
39 return c.json(messages);
40});
41
42app.post("/api/messages", async (c) => {
43 const { content } = await c.req.json();
44