bragreel
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data ā all from the browser, and deployed in milliseconds.
This directory contains modular route handlers for the API.
favicon.ts
: Handles the/favicon
endpoint for extracting favicons from URLs
To add a new route:
- Create a new file in this directory (e.g.,
myRoute.ts
) - Use the following template:
import { Hono } from "https://esm.sh/hono@3.11.7";
// Create a router for the endpoint
const router = new Hono();
// Define your routes
router.get("/", (c) => {
// Handler logic
return c.json({ message: "Your response" });
});
router.post("/", async (c) => {
// Handler logic for POST
const body = await c.req.json();
// Process the request
return c.json({ result: "Your response" });
});
// Export the router
export default router;
- Import and mount your router in the main
index.tsx
file:
import myRouter from "./routes/myRoute.ts";
// Mount the router
app.route("/my-route", myRouter);
This modular approach helps keep the codebase organized and maintainable as the API grows.
Get started with a template: