The Deno adapter provides utilities for running Hono applications on Deno, including static file serving, SSG support, and WebSocket handling.
Import
Functions
serveStatic()
Middleware for serving static files from the local file system in Deno.
Parameters
options.root - string (optional) - Root directory path (default: '.')
options.path - string (optional) - Base path for static files
options.rewriteRequestPath - (path: string) => string (optional) - Function to rewrite request paths
- Additional options from base
ServeStaticOptions
Example
upgradeWebSocket()
Helper function to upgrade HTTP connections to WebSocket connections in Deno.
Parameters
createEvents - Function that receives context and returns WebSocket event handlers:
onOpen - Called when the connection is established
onMessage - Called when a message is received
onClose - Called when the connection closes
onError - Called on error
options - Deno-specific WebSocket upgrade options (optional)
Example
toSSG()
toSSG is an experimental feature. The API might be changed.
Generates static HTML files from your Hono application (Static Site Generation).
Parameters
app - The Hono application instance
options - SSG options:
dir - string (optional) - Output directory (default: './static')
beforeRequestHook - (req: Request) => Request | false (optional)
afterResponseHook - (res: Response) => Response | false (optional)
afterGenerateHook - (result: ToSSGResult) => void | Promise<void> (optional)
Example
denoFileSystemModule
denoFileSystemModule is an experimental feature. The API might be changed.
File system module implementation for Deno, used by toSSG.
Interface
getConnInfo()
Extracts connection information from the Deno request.
Returns
Example
- Deno uses
Deno.open() and Deno.lstatSync() for file operations
- Connection information is extracted from
c.env.remoteAddr
- WebSocket support uses
Deno.upgradeWebSocket()
- SSG functionality uses Deno’s file system APIs
- Deno requires explicit permissions:
--allow-read for serving static files
--allow-write for SSG
--allow-net for serving HTTP
Running Your Application
See Also