honoExampleBkndREADME.md2 matches
1# Hono
23Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It works great!
4511- [Nhttp](https://www.val.town/v/tmcw.nhttpExample)
1213Migrated from folder: Web_API/honoExample
honoExampleREADME.md2 matches
1# Hono
23Here's an example using the [Hono](https://hono.dev/) server library with the [Web API](https://docs.val.town/api/web). It works great!
4511- [Nhttp](https://www.val.town/v/tmcw.nhttpExample)
1213Migrated from folder: Web_API/honoExample
untitled-8413index.ts26 matches
1import { Hono } from "https://esm.sh/hono@3.11.7";
2import { readFile, serveFile } from "https://esm.town/v/std/utils@85-main/index.ts";
3import type { ValTownVal, ValListResponse, ApiResponse } from "../shared/types.ts";
45const app = new Hono();
20});
2122// API endpoint to fetch user's vals
23app.get("/api/vals", async c => {
24try {
25const apiToken = Deno.env.get('VALTOWN_API_TOKEN');
26
27if (!apiToken) {
28return c.json<ApiResponse<null>>({
29success: false,
30error: "Val Town API token not configured. Please set VALTOWN_API_TOKEN environment variable."
31}, 400);
32}
3334// Fetch vals from Val Town API
35const response = await fetch('https://api.val.town/v2/me/vals', {
36headers: {
37'Authorization': `Bearer ${apiToken}`,
38'Content-Type': 'application/json'
39}
4142if (!response.ok) {
43throw new Error(`Val Town API error: ${response.status} ${response.statusText}`);
44}
4548// Process vals and add basic information
49const processedVals = valsData.data.map(val => {
50// For now, we'll set a default type since the v2 API doesn't include it
51// We can try to infer it from the val name or other clues
52val.type = 'script'; // Default type
53
54// Simple heuristic: if the val name suggests it's an HTTP endpoint
55if (val.name.toLowerCase().includes('api') ||
56val.name.toLowerCase().includes('server') ||
57val.name.toLowerCase().includes('web') ||
64});
6566return c.json<ApiResponse<ValTownVal[]>>({
67success: true,
68data: processedVals
71} catch (error) {
72console.error('Error fetching vals:', error);
73return c.json<ApiResponse<null>>({
74success: false,
75error: error instanceof Error ? error.message : 'Unknown error occurred'
78});
7980// API endpoint to get a specific val's details
81app.get("/api/vals/:id", async c => {
82try {
83const apiToken = Deno.env.get('VALTOWN_API_TOKEN');
84const valId = c.req.param('id');
85
86if (!apiToken) {
87return c.json<ApiResponse<null>>({
88success: false,
89error: "Val Town API token not configured"
90}, 400);
91}
9293const response = await fetch(`https://api.val.town/v1/vals/${valId}`, {
94headers: {
95'Authorization': `Bearer ${apiToken}`,
96'Content-Type': 'application/json'
97}
99100if (!response.ok) {
101throw new Error(`Val Town API error: ${response.status} ${response.statusText}`);
102}
103109}
110111return c.json<ApiResponse<ValTownVal>>({
112success: true,
113data: val
116} catch (error) {
117console.error('Error fetching val:', error);
118return c.json<ApiResponse<null>>({
119success: false,
120error: error instanceof Error ? error.message : 'Unknown error occurred'
untitled-8413types.ts1 match
32}
3334export interface ApiResponse<T> {
35success: boolean;
36data?: T;
untitled-8413index.html7 matches
50try {
51setLoading(true);
52const response = await fetch('/api/vals');
53const result = await response.json();
54
109110if (error) {
111const isTokenError = error.includes('API token not configured');
112return h('div', { className: 'flex items-center justify-center min-h-screen' },
113h('div', { className: 'text-center max-w-lg mx-auto p-6' },
114h('div', { className: 'text-red-500 text-6xl mb-4' }, isTokenError ? '🔑' : '⚠️'),
115h('h2', { className: 'text-xl font-semibold text-gray-900 mb-2' },
116isTokenError ? 'API Token Required' : 'Error Loading Vals'
117),
118h('p', { className: 'text-gray-600 mb-4' }, error),
121h('ol', { className: 'text-sm text-blue-800 space-y-1 list-decimal list-inside' },
122h('li', null, 'Go to ', h('a', {
123href: 'https://www.val.town/settings/api',
124target: '_blank',
125className: 'underline hover:text-blue-600'
126}, 'Val Town API Settings')),
127h('li', null, 'Create a new API token'),
128h('li', null, 'Set VALTOWN_API_TOKEN environment variable'),
129h('li', null, 'Refresh this page')
130)
untitled-8413README.md5 matches
12## Structure
1314- `backend/index.ts` - Main Hono server with API routes
15- `frontend/index.html` - Main web interface
16- `frontend/index.tsx` - React frontend application
19## Setup
20211. **Get your Val Town API token:**
22- Go to [Val Town Settings](https://www.val.town/settings/api)
23- Create a new API token
24- Copy the token
25262. **Set the environment variable:**
27- In your Val Town environment, set `VALTOWN_API_TOKEN` to your API token
28- The app will automatically fetch and display your vals
29
invest-trackercrypto_cron.tsx2 matches
11/* 1 ▸ Crypto with 7-day sparkline ------------------------------- */
12const ids = crypto.join(",");
13const url = `https://api.coingecko.com/api/v3/coins/markets`
14+ `?vs_currency=aud&ids=${ids}&sparkline=true`;
15const coins = await fetch(url, { headers: { "x-cg-demo-api-key": CG } }).then(r => r.json());
1617coins.forEach((c: any) => {
78for (const id of crypto) {
9const url = `https://api.coingecko.com/api/v3/coins/${id}`
10+ `/market_chart?vs_currency=aud&days=365&interval=daily`;
11
46app.post("/mcp", async (c) => {
47try {
48// Extract API token from headers
49const apiToken = c.req.header("X-Val-Town-Token") ||
50c.req.header("Authorization")?.replace("Bearer ", "")
5152if (!apiToken) {
53return c.json({
54jsonrpc: "2.0",
55error: {code: -32000, message: "Missing API token in X-Val-Town-Token header or Authorization header"},
56id: null
57}, 401)
60// Load remote configuration
61const config = await loadConfig(true)
62config.apiToken = apiToken
6364console.log({apiToken})
65// Convert Hono request to Node.js-style req/res
66const {req, res} = toReqRes(c.req.raw)
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: {