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
2022-07-10 18:52:04 +09:00
..
index.ts feat: support Deno! (#336) 2022-07-02 15:09:45 +09:00
module.mts feat: support Deno! (#336) 2022-07-02 15:09:45 +09:00
README.md feat: support Deno! (#336) 2022-07-02 15:09:45 +09:00
serve-static.ts chore: denoify 2022-07-10 18:52:04 +09:00

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

Example

https://github.com/honojs/examples/tree/master/serve-static