WIP! A BB-style forum, on the ATmosphere! We're still working... we'll be back soon when we have something to show off!
node typescript hono htmx atproto
at main 44 lines 1.2 kB view raw
1import { Hono } from "hono"; 2import { requestLogger } from "@atbb/logger/middleware"; 3import { createApiRoutes } from "../routes/index.js"; 4import type { AppContext } from "./app-context.js"; 5 6/** 7 * Create the Hono application with routes and middleware. 8 * Routes can access the database and other services via the injected context. 9 */ 10export function createApp(ctx: AppContext) { 11 const app = new Hono(); 12 13 app.use("*", requestLogger(ctx.logger)); 14 15 // Global error handler for unhandled errors 16 app.onError((err, c) => { 17 ctx.logger.error("Unhandled error in route handler", { 18 path: c.req.path, 19 method: c.req.method, 20 error: err.message, 21 stack: err.stack, 22 }); 23 24 return c.json( 25 { 26 error: "An internal error occurred. Please try again later.", 27 ...(process.env.NODE_ENV !== "production" && { 28 details: err.message, 29 }), 30 }, 31 500 32 ); 33 }); 34 35 // OAuth client metadata endpoint 36 // Serve metadata from the OAuth client library 37 app.get("/.well-known/oauth-client-metadata", (c) => { 38 return c.json(ctx.oauthClient.clientMetadata); 39 }); 40 41 app.route("/api", createApiRoutes(ctx)); 42 43 return app; 44}