Skip to content
Myr

serve-static.ts

This file

Path

src/adapter/bun/serve-static.ts

35 lines · 1.0 KiB · TypeScript

Last changed by

feat(adapters): add @hono/bun as a workspace package (#5447)Yusuke Wadabefore adoptionfc2343d

History of this file

Take it

The walk stopped after 200 commits: lines older than f0b094d point at it.

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 1–7why, one step back
1/* eslint-disable @typescript-eslint/ban-ts-comment */
2import { stat } from 'node:fs/promises'3import { join } from 'node:path'4import { serveStatic as baseServeStatic } from '../../middleware/serve-static'5import type { ServeStaticOptions } from '../../middleware/serve-static'6import type { Env, MiddlewareHandler } from '../../types'7

feat(adapters): add @hono/bun as a workspace package (#5447)Yusuke Wadabefore adoptionfc2343d

lines 8–10why, one step back
8/**
9 * @deprecated `hono/bun` will be removed in v5. Install `@hono/bun` and import from there instead.10 */

Merge commit from forkYusuke Wadabefore adoptionf0b094d

lines 11–35why, one step back
11export const serveStatic = <E extends Env = Env>(
12 options: ServeStaticOptions<E> = {}13): MiddlewareHandler => {14 return async function serveStatic(c, next) {15 const getContent = async (path: string) => {16 // @ts-ignore17 const file = Bun.file(path)18 return (await file.exists()) ? file : null19 }20 const isDir = async (path: string) => {21 let isDir22 try {23 const stats = await stat(path)24 isDir = stats.isDirectory()25 } catch {}26 return isDir27 }28 return baseServeStatic({29 ...options,30 getContent,31 join,32 isDir,33 })(c, next)34 }35}