0
0
mirror of https://github.com/honojs/hono.git synced 2024-12-01 11:51:01 +01:00
hono/deno_dist/middleware/serve-static/README.md

57 lines
939 B
Markdown
Raw Normal View History

2022-07-02 08:09:45 +02:00
# Serve Static Middleware
Serve Static Middleware is available only on Cloudflare Workers.
## Usage
index.ts:
```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:
```ts
import { Hono } from 'hono'
import { serveStatic } from 'hono/serve-static.module' // <---
const app = new Hono()
//...
export default app
```
wrangler.toml:
```toml
[site]
bucket = "./assets"
```
Asset files:
```
./assets
└── static
├── demo
│   └── index.html
├── hello.txt
├── fallback.txt
└── images
└── dinotocat.png
```
## Example
<https://github.com/honojs/examples/tree/master/serve-static>