202});
203
204// HTTP vals expect an exported "fetch handler"
205// This is how you "run the server" in Val Town with Hono
206export default app.fetch;
25 }
26
27 const response = await fetch(`/fork?url=${encodeURIComponent(projectUrl)}`, {
28 method: "POST",
29 headers: {
14}
15
16async function fetchPromos(): Promise<Promo[]> {
17 try {
18 const response = await fetch(FRONTIER_URL);
19 const html = await response.text();
20
109 return promos;
110 } catch (error) {
111 console.error("Failed to fetch promos:", error);
112 throw error;
113 }
118app.get("/", async (c) => {
119 try {
120 const promos = await fetchPromos();
121 return c.json({
122 success: true,
131 success: false,
132 timestamp: new Date().toISOString(),
133 error: error.message || "Failed to fetch promotions",
134 },
135 500,
141// deno-lint-ignore require-await
142export default async function server(request: Request): Promise<Response> {
143 return app.fetch(request);
144}
145
1import { modifyFetchHandler } from "https://esm.town/v/andreterron/codeOnValTown?v=50";
2import { form } from "https://esm.town/v/stevekrouse/date_me_form";
3import browse from "https://esm.town/v/stevekrouse/dateme_browse";
13app.get("/faq", faq);
14app.get("/rss.xml", c => dateMeRSS(c.req as unknown as Request));
15export default modifyFetchHandler(app.fetch, {
16 style: `@media (max-width: 500px) {
17 .github-fork-ribbon {
22app.fire();
23
24export default app.fetch;
5
6## What it does
7- Fetches technical data from Yahoo
8- Searches the web like "good stocks to buy"
9- Makes confident recommendations with the conviction of someone
63/**
64 * Wrap the incoming request, inject the Deno env vars into the Hono app,
65 * and then call the Hono api entrypoint (`app.fetch`)
66 */
67export default async function(req: Request): Promise<Response> {
74 //
75 // If you don't want those values, remove them from the env object
76 return app.fetch(req, env);
77}
21});
22
23// HTTP vals expect an exported "fetch handler"
24// This is how you "run the server" in Val Town with Hono
25export default app.fetch;
264 } else {
265 // Otherwise, return the complete response
266 return await fetchChatResponse(openaiMessages, apiKey);
267 }
268}
269
270/**
271 * Fetch a complete chat response from OpenAI
272 */
273async function fetchChatResponse(messages: any[], apiKey: string): Promise<string> {
274 try {
275 const response = await fetch("https://api.openai.com/v1/chat/completions", {
276 method: "POST",
277 headers: {
300 return data.choices[0]?.message?.content || "Sorry, I couldn't generate a response.";
301 } catch (error) {
302 console.error("Error in fetchChatResponse:", error);
303 throw error;
304 }
310async function streamChatResponse(messages: any[], apiKey: string, stream: any): Promise<string> {
311 try {
312 const response = await fetch("https://api.openai.com/v1/chat/completions", {
313 method: "POST",
314 headers: {
392app.use(router.allowedMethods());
393
394// HTTP vals expect an exported "fetch handler"
395export default app.handle;
184 const messagesToSend = [...messages, userMessage];
185
186 const response = await fetch("/api/chat/complete", {
187 method: "POST",
188 headers: { "Content-Type": "application/json" },