Skip to main content
Module

x/hono/adapter/deno/serve-static.ts

Web Framework built on Web Standards
Extremely Popular
Go to Latest
File
import type { ServeStaticOptions } from '../../middleware/serve-static/index.ts'import { serveStatic as baseServeStatic } from '../../middleware/serve-static/index.ts'import type { Env, MiddlewareHandler } from '../../types.ts'
// eslint-disable-next-line @typescript-eslint/ban-ts-comment// @ts-ignoreconst { open } = Deno
export const serveStatic = <E extends Env = Env>( options: ServeStaticOptions<E>): MiddlewareHandler => { return async function serveStatic(c, next) { const getContent = async (path: string) => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let file: any try { file = await open(path) } catch (e) { console.warn(`${e}`) } return file ? file.readable : undefined } const pathResolve = (path: string) => { return `./${path}` } return baseServeStatic({ ...options, getContent, pathResolve, })(c, next) }}