hono
hono copied to clipboard
feat: expose serve-static builder
This allows accessing middleware/serve-static from third-party
Use case
I run my own handler based on Cloudflare R2 to avoid the limitations of Cloudflare KV / Pages. And I found that most of the code I needed there was already built into hono.
So what I expect is like:
import { Hono } from 'hono';
import { serveStatic as makeServe } from 'hono/base-serve-static';
const app = new Hono<Env>();
const serveContent = makeServe<Env>({
getContent: async (path, c) => {
// retrieve
let response = await cache.match(c.req.raw);
// ...get R2 object
if (!response) {
let obj = await c.env.CONTENT.get(path);
if (obj) {
response = obj.body;
c.executionCtx.waitUntil(cache.put(c.req.raw, obj.body));
}
}
c.body(response);
},
});
app.use(serveContent);
export default app;
Author should do the followings, if applicable
- [ ] Add tests
- [x] Run tests
- [x]
yarn denoifyto generate files for Deno
Hi @cometkim
This is good! But please wait until I look over the details!
@yusukebe added a type definition rather than any as it would be a public interface.
And made some changes to allow a situation where users needed to create the Response object themselves. (e.g. using with Browser/Cloudflare's Cache API)
@cometkim Thanks!