5## Project Structure
6
7- `backend/` - Hono API server
8- `frontend/` - React frontend with val showcase
9- `shared/` - Shared types and utilities
18## Development
19
20The main entry point is `backend/index.ts` which serves the frontend and API routes.
2import { PDFDocument } from "https://esm.sh/pdf-lib@1.17.1";
3import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
4import type { SplitRequest, MergeRequest, ApiResponse } from "../shared/types.ts";
5
6const app = new Hono();
48
49// Split PDF endpoint
50app.post("/api/split", async c => {
51 try {
52 const body: SplitRequest = await c.req.json();
78 const base64Result = btoa(String.fromCharCode(...newPdfBytes));
79
80 const response: ApiResponse = {
81 success: true,
82 data: base64Result,
86 return c.json(response);
87 } catch (error) {
88 const response: ApiResponse = {
89 success: false,
90 error: error instanceof Error ? error.message : 'Unknown error occurred'
95
96// Merge PDF endpoint
97app.post("/api/merge", async c => {
98 try {
99 const body: MergeRequest = await c.req.json();
126 const base64Result = btoa(String.fromCharCode(...mergedPdfBytes));
127
128 const response: ApiResponse = {
129 success: true,
130 data: base64Result,
134 return c.json(response);
135 } catch (error) {
136 const response: ApiResponse = {
137 success: false,
138 error: error instanceof Error ? error.message : 'Unknown error occurred'
143
144// Health check endpoint
145app.get("/api/health", c => {
146 return c.json({ status: "ok", timestamp: new Date().toISOString() });
147});
15}
16
17export interface ApiResponse {
18 success: boolean;
19 data?: string; // base64 encoded result PDF
14```
15โโโ backend/
16โ โโโ index.ts # Main Hono server with API routes
17โ โโโ README.md # Backend documentation
18โโโ frontend/
30```
31
32## API Endpoints
33
34- `GET /` - Serve the main application
35- `POST /api/split` - Split a PDF file
36- `POST /api/merge` - Merge multiple PDF files
37- `GET /frontend/*` - Serve frontend assets
38- `GET /shared/*` - Serve shared assets
2 const NOCODB_BASE_URL = "https://dynamopm.welike.solutions";
3 const TABLE_ID = "mgcw4owm7x2cwnp";
4 const API_TOKEN = Deno.env.get("DYNAMOPM_NOCODB_API_KEY");
5
6 if (!API_TOKEN) {
7 console.error("API token not found. Please set DYNAMOPM_NOCODB_API_KEY environment variable.");
8 return;
9 }
14 // and limit=1 to get only one record
15 const response = await fetch(
16 `${NOCODB_BASE_URL}/api/v2/tables/${TABLE_ID}/records?sort=-Id&limit=1`,
17 {
18 method: "GET",
19 headers: {
20 "xc-token": API_TOKEN,
21 "Content-Type": "application/json",
22 },
25
26 if (!response.ok) {
27 console.error(`API request failed with status: ${response.status}`);
28 const errorText = await response.text();
29 console.error("Error details:", errorText);
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
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