vtEditorFiles-fixvaltown.mdc9 matches
18- Generate code in TypeScript or TSX
19- Add appropriate TypeScript types and interfaces for all data structures
20- Prefer official SDKs or libraries than writing API calls directly
21- Ask the user to supply API or library documentation if you are at all unsure about it
22- **Never bake in secrets into the code** - always use environment variables
23- Include comments explaining complex logic (avoid commenting obvious operations)
28### 1. HTTP Trigger
2930- Create web APIs and endpoints
31- Handle HTTP requests and responses
32- Example structure:
163- **AI Image:** To inline generate an AI image use: `<img src="https://maxm-imggenurl.web.val.run/the-description-of-your-image" />`
164- **Storage:** DO NOT use the Deno KV module for storage
165- **Browser APIs:** DO NOT use the `alert()`, `prompt()`, or `confirm()` methods
166- **Weather Data:** Use open-meteo for weather data (doesn't require API keys) unless otherwise specified
167- **Error Debugging:** Add `<script src="https://esm.town/v/std/catch"></script>` to HTML to capture client-side errors
168- **Error Handling:** Only use try...catch when there's a clear local resolution; Avoid catches that merely log or return 500s. Let errors bubble up with full context
169- **Environment Variables:** Use `Deno.env.get('keyname')` when you need to, but generally prefer APIs that don't require keys
170- **Imports:** Use `https://esm.sh` for npm and Deno dependencies to ensure compatibility on server and browser
171- **Storage Strategy:** Only use backend storage if explicitly required; prefer simple static client-side sites
205### Backend (Hono) Best Practices
206207- Hono is the recommended API framework
208- Main entry point should be `backend/index.ts`
209- Do NOT use Hono serveStatic middleware
230});
231```
232- Create RESTful API routes for CRUD operations
233- Always include this snippet at the top-level Hono app to re-throwing errors to see full stack traces:
234```ts
267- For files in the project, use `readFile` helpers
2682695. **API Design:**
270- `fetch` handler is the entry point for HTTP vals
271- Run the Hono app with `export default app.fetch // This is the entry point for HTTP vals`
GIthubProfileindex.tsx7 matches
309<div className="bg-white rounded-lg shadow-sm p-6">
310<h2 className="text-xl font-bold text-gray-800 mb-4 flex items-center gap-2">
311๐ Raw API Responses
312</h2>
313<p className="text-gray-600 mb-4 text-sm">
314Click on any section below to view the raw JSON response from GitHub's API
315</p>
316<div className="space-y-4">
321className="w-full px-4 py-3 text-left bg-gray-50 hover:bg-gray-100 rounded-t-lg flex items-center justify-between transition-colors"
322>
323<span className="font-semibold text-gray-700 capitalize">
324{key} API Response ({key === 'user' ? '1 object' : `${Array.isArray(data) ? data.length : 1} items`})
325</span>
326<span className="text-gray-500">
339</div>
340<div className="mt-4 p-3 bg-blue-50 rounded-lg text-sm text-blue-800">
341<strong>๐ก API Information:</strong> This data is fetched from GitHub's REST API v3.
342The APIs used are: <code>/users/{`{username}`}</code>, <code>/users/{`{username}`}/repos</code>,
343and <code>/users/{`{username}`}/events/public</code>.
344</div>
362363try {
364const response = await fetch(`/api/user/${encodeURIComponent(searchUsername.trim())}`);
365const data = await response.json();
366
GIthubProfileindex.ts18 matches
18});
1920// GitHub API interfaces
21interface GitHubUser {
22login: string;
75}
7677// Helper function to make GitHub API requests
78async function fetchGitHubAPI(endpoint: string): Promise<any> {
79const headers: Record<string, string> = {
80'Accept': 'application/vnd.github.v3+json',
88}
8990const response = await fetch(`https://api.github.com${endpoint}`, {
91headers
92});
101if (rateLimitRemaining === '0') {
102const resetTime = rateLimitReset ? new Date(parseInt(rateLimitReset) * 1000).toLocaleTimeString() : 'unknown';
103throw new Error(`GitHub API rate limit exceeded. Resets at ${resetTime}. Consider adding a GITHUB_TOKEN environment variable for higher limits.`);
104}
105throw new Error('GitHub API access forbidden. This might be due to rate limiting.');
106}
107throw new Error(`GitHub API error: ${response.status} ${response.statusText}`);
108}
109111}
112113// API endpoint to fetch GitHub user profile data
114app.get("/api/user/:username", async c => {
115try {
116const username = c.req.param("username");
121122// Fetch user data
123const userResponse = await fetchGitHubAPI(`/users/${username}`);
124
125// Fetch user's repositories (latest 10, sorted by updated)
126const reposResponse = await fetchGitHubAPI(`/users/${username}/repos?sort=updated&per_page=10`);
127
128// Fetch user's recent public events (latest 10)
129const eventsResponse = await fetchGitHubAPI(`/users/${username}/events/public?per_page=10`);
130131const profileData: GitHubProfileData = {
155});
156157// Demo data for when API is rate limited
158function getDemoData(): GitHubProfileData {
159const demoUser = {
189updated_at: "2023-12-07T21:00:00Z",
190created_at: "2011-01-26T19:01:12Z",
191topics: ["octocat", "atom", "electron", "api"]
192},
193{
213repo: {
214name: "octocat/Hello-World",
215url: "https://api.github.com/repos/octocat/Hello-World"
216},
217payload: {
229repo: {
230name: "github/docs",
231url: "https://api.github.com/repos/github/docs"
232},
233payload: {}
240events: demoEvents,
241rawResponses: {
242user: { ...demoUser, _note: "Demo data - API rate limited" },
243repos: [...demoRepos],
244events: [...demoEvents]
248249// Health check endpoint
250app.get("/api/health", c => {
251return c.json({ status: "ok", timestamp: new Date().toISOString() });
252});
GIthubProfileREADME.md10 matches
1# GitHub User Profile Viewer
23A web application that displays comprehensive GitHub user profiles with detailed information cards and raw API responses.
45## Features
8- **Statistics**: Shows followers, following, public repos, and gists
9- **Activity Data**: Recent repositories and contribution stats
10- **Raw API Responses**: Shows all GitHub API responses used to build the profile
11- **Responsive Design**: Works on desktop and mobile devices
1215```
16โโโ backend/
17โ โโโ index.ts # Main API server with GitHub data fetching
18โโโ frontend/
19โ โโโ index.html # Main HTML template
23```
2425## GitHub APIs Used
2627- **User API**: `/users/{username}` - Basic user information
28- **User Repos API**: `/users/{username}/repos` - User's repositories
29- **User Events API**: `/users/{username}/events/public` - Recent activity
3031## Usage
331. Enter a GitHub username in the search field
342. View the formatted profile card with user details
353. Scroll down to see raw API responses for transparency
3637## Tech Stack
3839- **Backend**: Hono (TypeScript API framework)
40- **Frontend**: React with TypeScript
41- **Styling**: TailwindCSS
42- **APIs**: GitHub REST API v4
17let html = await readFile("/frontend/index.html", import.meta.url);
1819const response = await fetch(`/api/demo/${id}`);
20const initialData = await response.json();
2187// Client-side event recording
88window.recordClick = function (action) {
89fetch(`/api/setAction`, {
90method: "POST",
91headers: { "Content-Type": "application/json" },
103104```
105โโโ backend/ # Server-side logic and API routes
106โ โโโ controllers/ # Business logic for Notion integration
107โ โโโ crons/ # Scheduled tasks for cache management
108โ โโโ routes/ # HTTP route handlers
109โ โ โโโ api/ # JSON API endpoints
110โ โ โโโ tasks/ # Notion webhook handlers
111โ โ โโโ views/ # HTML page serving
121### Backend (`/backend`)
122123Handles all server-side operations including API routes, Notion integration, and static file serving. Built with Hono for routing and includes authentication middleware.
124125### Frontend (`/frontend`)
134135- **Val Town & Deno**: Serverless runtime environment with TypeScript support
136- **Notion Client**: Official npm library for Notion API integration
137- **Hono**: Lightweight web framework for routing and middleware
138- **Blob Storage**: Val Town's built-in caching solution for performance optimization
170171// Route modules
172app.route("/api", api); // JSON API endpoints
173app.route("/tasks", tasks); // Notion webhook handlers
174app.route("/demo", demo); // Demo page serving
175```
176177#### API Routes (`/api`)
178179Serve JSON data and handle CRUD operations for demo management, cobrowsing status, and user interactions.
241```typescript
242const notion = new Client({
243auth: Deno.env.get("NOTION_API_KEY"),
244});
245249Required environment variables:
250251- `NOTION_API_KEY`: Notion integration token
252- `GLANCE_DEMOS_DB_ID`: Notion database ID for demo pages
253- `GLANCE_INTERACTIONS_DB_ID`: Notion database ID for interaction tracking
289Different route areas serve specific purposes:
290291- `/api/*`: JSON data endpoints for frontend consumption
292- `/demo/*`: Personalized demo page serving with data injection
293- `/tasks/*`: Notion webhook processing and database updates
GlancerpollEnabledStatus.ts1 match
1213// check the boolean to see if a Glancer has enabled the link to start a cobrowsing session
14const resp = await fetch("/api/cobrowse/" + window.__DEMO_ID__, {
15method: "GET",
16headers: {
78// Import route modules
9import api from "./routes/api/api.routes.ts";
10import auth from "./routes/auth.ts";
11import root from "./routes/root.routes.ts";
3435// Mount route modules
36app.route("/api", api);
37app.route("/tasks", tasks);
38app.route("/demo", demo);
Glancerindex.html1 match
9<script src="https://cdn.tailwindcss.com"></script>
10<link
11href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap"
12rel="stylesheet"
13/>
GlancerhealthCheck.ts2 matches
5// Initialize Notion client
6const notion = new Client({
7auth: Deno.env.get("NOTION_API_KEY"),
8});
911return {
12status: "connected",
13message: "Successfully connected to Notion API",
14databases: response.results.map((db) => ({
15title: db.title?.[0]?.plain_text || "Untitled",
GlancerdemoCache.ts1 match
6// Initialize Notion client
7const notion = new Client({
8auth: Deno.env.get("NOTION_API_KEY"),
9});
10