27 */
28export async function generateCourseStructure(prompt: string): Promise<CourseStructure> {
29 // Check for OpenAI API key
30 const apiKey = Deno.env.get("OPENAI_API_KEY");
31 if (!apiKey) {
32 console.error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable in Val Town.");
33 throw new Error("OpenAI API key is missing. Please set the OPENAI_API_KEY environment variable in Val Town.");
34 }
35
16โ โโโ index.ts # Main entry point with Hono setup
17โ โโโ routes/
18โ โโโ highlighter-route.ts # Highlighter API route
19โโโ frontend/
20โ โโโ components/
37## Usage
38
39Visit the frontend page to customize and generate syntax-highlighted images. The API endpoint is available at `/api/highlighter` with the following parameters:
40
41- `code`: The code to highlight
12});
13
14// API routes
15app.get("/api/highlighter", highlighterHandler);
16
17// Serve static files
16): string {
17 return (
18 `${baseUrl}/api/highlighter?code=` +
19 encodeURIComponent(code) +
20 '&background=' +
19}
20
21// API response interfaces
22export interface ApiResponse<T> {
23 success: boolean;
24 data?: T;
32 * Compiles TypeScript to JavaScript
33 * This is a simple implementation that doesn't use the TypeScript compiler
34 * In a real-world scenario, you would use the TypeScript compiler API
35 */
36export function compileTypeScript(tsCode: string): string {
19 clearTimeout(timeoutId);
20
21 // Unfortunately, the fetch API doesn't give us direct access to the certificate
22 // So we need to use the tls module in Node.js or Deno's TLS APIs
23
24 // For Val Town, we can use Deno's TLS connect function
4import { npmPackageRoute } from "./routes/npm-package.ts";
5
6export const apiRoute = new Hono()
7 .route("/search", searchRoute)
8 .route("/package", packageRoute)
9 .route("/npm-package", npmPackageRoute);
10
11export type AppType = typeof apiRoute;
12
5 const host = "www.cdatacloud.net";
6
7 const analyzeRes = await fetch(`https://api.ssllabs.com/api/v3/analyze?host=${host}`);
8 const analyzeJson = await analyzeRes.json();
9
18
19 const endpointRes = await fetch(
20 `https://api.ssllabs.com/api/v3/getEndpointData?host=${host}&ip=${endpoint.ipAddress}`,
21 );
22 const endpointJson = await endpointRes.json();
24
25- Built on Val Town using TypeScript
26- Uses OpenAI's API for prompt expansion
27- Responsive design with Twind (Tailwind CSS in JS)
28- Error handling for API failures
29
30## Technical Stack