HonoDenoVite
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.
Viewing readonly version of main branch: v51View latest version
A Vite project running on Val Town with Hono for API routes and server-side rendering. The server.tsx
serves the project and handles both static assets and API requests.
This project uses:
- Vite: For bundling and development
- Deno: As the runtime environment
- React: For UI components
- Hono: For server-side routing and API endpoints
- TypeScript: For type safety
The application has two main components:
-
Server-side (Hono): Handles API requests and server-side rendering
- Defined in
src/index.tsx
- Exports a Hono app that handles routes and API endpoints
- Defined in
-
Client-side (React): Provides interactive UI components
- Defined in
src/client.tsx
- Uses Hono's client to communicate with the API
- Defined in
The server handles requests in two ways:
- Static assets: Proxied to the Vite build server
// For static assets (JS, CSS, etc.)
if (url.pathname.startsWith("/static/") || url.pathname.endsWith(".js")) {
const path = `/${projectVal.username}/${projectVal.name}@${projectVal.version}${url.pathname}`;
const proxyUrl = new URL(path, "https://vite-proxy.ng-demo.valtown.net").toString();
const response = await fetch(proxyUrl);
// ...return the response
}
- API and page routes: Handled by the Hono app
If you encounter issues:
- Check the server logs: Look for error messages in the console
- Verify import paths: Make sure all imports use the correct format (npm: prefix)
- Check for duplicate exports: Ensure there are no duplicate export statements
- Content types: Make sure content types are correctly set for all assets
To make changes:
- Edit the Hono routes in
src/index.tsx
- Update client-side components in
src/client.tsx
- The server will rebuild on the next request