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
200 const url = new URL(req.url);
201
202 // Handle the expand API endpoint
203 if (url.pathname === "/expand") {
204 if (req.method !== "POST") {
3import { hc } from "https://esm.sh/hono@4.7.7/client?deps=hono@4.7.7";
4import { QueryClient } from "https://esm.sh/@tanstack/react-query@5.74.7?deps=react@19.0.0";
5import { AppType } from "../backend/api/mod.ts";
6import { APP_URL } from "../shared/consts.ts";
7
8export const client = hc<AppType>(
9 typeof window !== "undefined"
10 ? window.location.origin + "/api"
11 : APP_URL + "/api",
12 { init: { credentials: "include" } },
13);
7- Expands even single-word prompts into rich, detailed content
8- Simple, clean user interface with example suggestions
9- Real-time prompt expansion using OpenAI's API
10- Responsive design that works on mobile and desktop
11- Error handling and loading states
46## Notes
47
48This application uses the OpenAI API which requires an API key. Make sure your Val Town account has an OpenAI API key configured in the environment variables.
2
3export default async function (req: Request): Promise<Response> {
4 // Handle API requests for prompt expansion
5 if (req.url.includes("/api/expand") && req.method === "POST") {
6 try {
7 const { prompt } = await req.json();
199
200 try {
201 const response = await fetch('/api/expand', {
202 method: 'POST',
203 headers: {
37
38- Built as an HTTP-triggered Val in Val Town
39- Uses OpenAI's API to generate prompts
40- Frontend styled with TailwindCSS
41- Handles both GET and POST requests in a single endpoint
42- Includes error handling for API failures
43
44## Setup
46To use this application, you need to:
47
481. Set up an OpenAI API key as an environment variable in Val Town
492. Deploy the Val with HTTP trigger enabled
50
51## Environment Variables
52
53- `OPENAI_API_KEY`: Your OpenAI API key for generating prompts
54
55## Customization