54
55// Dynamically import the handler
56let fetchHandler;
57try {
58 // deno-lint-ignore unanalyzable-dynamic-import
59 const handlerModule = await import(args.handler);
60 if (!handlerModule?.default?.fetch) {
61 throw new Error(
62 "Handler module must export default {fetch...} like in https://docs.deno.com/api/deno/~/Deno.ServeDefaultExport",
63 );
64 }
65 fetchHandler = handlerModule.default.fetch;
66} catch (error) {
67 const errorMessage = error instanceof Error ? error.message : String(error);
96try {
97 console.log(`Starting server on port ${args.port}...`);
98 await Deno.serve({ cert, key, port, reusePort: true }, fetchHandler);
99} catch (error) {
100 if (error instanceof Deno.errors.PermissionDenied) {
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
183
184 try {
185 const response = await fetch("/", {
186 method: "POST",
187 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
182
183 try {
184 const response = await fetch("/", {
185 method: "POST",
186 body: JSON.stringify({
1/** @jsxImportSource https://esm.sh/hono/jsx */
2
3import { fetchPaginatedData } from "https://esm.town/v/nbbaier/fetchPaginatedData?v=49";
4import { api } from "https://esm.town/v/pomdtr/api?v=12";
5import { extractValInfo } from "https://esm.town/v/pomdtr/extractValInfo";
182 authenticated: true,
183 });
184 const vals = await fetchPaginatedData(`${API_URL}/v1/users/${id}/vals`, {
185 headers: {
186 Authorization: `Bearer ${Deno.env.get("valtown")}`,
256});
257
258export default app.fetch;
259
27 const authHeader = req.headers.get("Proxy-Authorization") || req.headers.get("Authorization");
28 const token = authHeader ? parseBearerString(authHeader) : undefined;
29 const meRes = await fetch(`${API_URL}/v1/me`, { headers: { Authorization: `Bearer ${token}` } });
30 if (!meRes.ok) {
31 return new Response("Unauthorized", { status: 401 });
63 });
64
65 const openAIRes = await fetch(url, {
66 method: req.method,
67 headers,