mirror of
https://github.com/honojs/hono.git
synced 2024-12-01 11:51:01 +01:00
939 B
939 B
Serve Static Middleware
Serve Static Middleware is available only on Cloudflare Workers.
Usage
index.ts:
import { Hono } from 'hono'
import { serveStatic } from 'hono/serve-static'
const app = new Hono()
app.use('/static/*', serveStatic({ root: './' }))
app.get('/', (c) => c.text('This is Home! You can access: /static/hello.txt'))
app.get('*', serveStatic({ path: './static/fallback.txt' }))
app.fire()
In Module Worker mode:
import { Hono } from 'hono'
import { serveStatic } from 'hono/serve-static.module' // <---
const app = new Hono()
//...
export default app
wrangler.toml:
[site]
bucket = "./assets"
Asset files:
./assets
└── static
├── demo
│ └── index.html
├── hello.txt
├── fallback.txt
└── images
└── dinotocat.png