1Fork this and set the endpoint as your VAL_TOWN_BASE_URL to intercept and inspect your api requests.
1import { Hono } from "npm:hono";
2import logApi from "../log-api.js";
3import { serveStatic } from "npm:hono/middleware";
4
6const app = new Hono();
7
8// Mount the log API
9app.route('/api', logApi);
10
11// Serve our main page
8
9// Store logs from the client
10app.post('/api/store-logs', async (c) => {
11 try {
12 const body = await c.req.json();
26
27// Get logs for a specific key
28app.get('/api/load-logs', (c) => {
29 try {
30 const key = c.req.query('key');
43
44// Get all available log keys
45app.get('/api/list-logs', (c) => {
46 try {
47 const keys = Array.from(logStore.keys());
111 try {
112 if (typeof window !== 'undefined' && window?.fetch) {
113 const response = await fetch('/api/store-logs', {
114 method: 'POST',
115 headers: { 'Content-Type': 'application/json' },
133 try {
134 if (typeof window !== 'undefined' && window?.fetch) {
135 const response = await fetch(`/api/load-logs?key=${this.storeKey}`);
136 if (response.ok) {
137 const data = await response.json();
24 - Ensure the token has read/write access to _Contents_ for the repo
25 - Copy the access token and add that as the `GITHUB_TOKEN` env var in this val
261. Add a new [Val Town API token][] with read/write permissions. Add that token to the val's env vars as `VALTOWN_TOKEN`
271. Add a `VAL_SECRET` env var to the val. Use this secret to sign the webhook POST request to the `/push` endpoint. Use this endpoint to commit vals from Val Town to your GitHub repo.
28
68
69- `GITHUB_TOKEN`: Read/write GitHub personal access token for reading and writing repo contents
70- `VALTOWN_TOKEN`: ValTown API token (with read/write Vals permissions) for writing updates from GitHub
71- `GITHUB_WEBHOOK_SECRET`: secret for verifying webhooks from GitHub
72- `VAL_SECRET`: secret for verifying requests to the `/push` endpoint
98[github oauth app]: https://github.com/settings/developers
99[access token]: https://github.com/settings/tokens
100[val town api token]: https://www.val.town/settings/api
101[troubleshooting]: #troubleshooting
102
28 const url = new URL(req.url);
29
30 if (req.method == "POST" && url.pathname == "/api/board") {
31 const { clickedCell }: { grid: boolean[][]; clickedCell: { row: number; col: number } } = await req
32 .json();
53 const handleClick = async (row, col) => {
54 try {
55 const response = await fetch("/api/board", {
56 method: "POST",
57 headers: {
3import { ITERATIONS_TABLE, KEY, PROJECTS_TABLE, SCHEMA_VERSION } from "./migrations";
4
5const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") });
6
7export async function createProject(prompt: string) {
3import { ITERATIONS_TABLE, KEY, PROJECTS_TABLE, SCHEMA_VERSION } from "./migrations";
4
5const openai = new OpenAI({ apiKey: Deno.env.get("OPENAI_API_KEY") });
6
7export async function createProject(prompt: string) {
17 } else {
18 const openai = new OpenAI({
19 apiKey: Deno.env.get(
20 "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",
21 ),