79 // This is a no-op if nothing's changed
80 if (!isEndpointSet) {
81 await bot.api.setWebhook(req.url, {
82 secret_token: SECRET_TOKEN,
83 });
2import moment from "npm:moment-timezone";
3
4// Reddit API credentials
5const clientId = "-ngsEqbToTa_FlVv-Uy28g";
6const clientSecret = "iE3aFgBYsZvCZmyLWOlAhI9pFAQ2-g";
9async function getAccessToken() {
10 const response = await axios.post(
11 "https://www.reddit.com/api/v1/access_token",
12 new URLSearchParams({
13 grant_type: "client_credentials", // Use client credentials flow
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.
887 <meta name="viewport" content="width=device-width, initial-scale=1.0">
888 <title>Character Creator - Select Race (Holographic Cards)</title>
889 <link rel="preconnect" href="https://fonts.googleapis.com">
890 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
891 <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;700;900&family=Orbitron:wght@700&display=swap" rel="stylesheet">
892 <style>${css}</style>
893</head>
79 // This is a no-op if nothing's changed
80 if (!isEndpointSet) {
81 await bot.api.setWebhook(req.url, {
82 secret_token: SECRET_TOKEN,
83 });
71 // This is a no-op if nothing's changed
72 if (!isEndpointSet) {
73 await bot.api.setWebhook(req.url, {
74 secret_token: SECRET_TOKEN,
75 });
12 },
13 {
14 "prompt": "weather dashboard for nyc using open-meteo API for NYC with icons",
15 "title": "Weather App",
16 "code":
8
91. Sign up for [Cerebras](https://cloud.cerebras.ai/)
102. Get a Cerebras API Key
113. Save it in your project env variable called `CEREBRAS_API_KEY`
211 } catch (error) {
212 Toastify({
213 text: "We may have hit our Cerebras Usage limits. Try again later or fork this and use your own API key.",
214 position: "center",
215 duration: 3000,
5 <meta name="viewport" content="width=device-width, initial-scale=1.0">
6 <title>CerebrasCoder</title>
7 <link rel="preconnect" href="https://fonts.googleapis.com" />
8 <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
9 <link
10 href="https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300;1,400;1,500&family=DM+Sans:ital,opsz,wght@0,9..40,100..1000;1,9..40,100..1000&display=swap"
11 rel="stylesheet"
12 />
21 <meta property="og:description" content="Turn your ideas into fully functional apps in less than a second – powered by Llama3.3-70b on Cerebras's super-fast wafer chips. Code is 100% open-source, hosted on Val Town."">
22 <meta property="og:type" content="website">
23 <meta property="og:image" content="https://stevekrouse-blob_admin.web.val.run/api/public/CerebrasCoderOG.jpg">
24
25