serve-static.ts
This file
Path
src/adapter/cloudflare-workers/serve-static.ts
45 lines · 1.6 KiB · TypeScript
Last changed by
feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827
History of this fileTake it
The walk stopped after 200 commits: lines older than f0b094d point at it.
Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 1–5why, one step back1import { serveStatic as baseServeStatic } from '../../middleware/serve-static'2import type { ServeStaticOptions as BaseServeStaticOptions } from '../../middleware/serve-static'3import type { Env, MiddlewareHandler } from '../../types'4import { getContentFromKVAsset } from './utils'5feat(adapters): add the seven adapters as workspace packages (#5463)Yusuke Wadabefore adoptionb877827
lines 6–8why, one step back6/**7 * @deprecated `hono/cloudflare-workers` will be removed in v5. Install `@hono/cloudflare-workers` and import from there instead.8 */Merge commit from forkYusuke Wadabefore adoptionf0b094d
lines 9–45why, one step back9export type ServeStaticOptions<E extends Env = Env> = BaseServeStaticOptions<E> & {10 // namespace is KVNamespace11 namespace?: unknown12 manifest?: object | string13}1415/**16 * @deprecated17 * `serveStatic` in the Cloudflare Workers adapter is deprecated.18 * You can serve static files directly using Cloudflare Static Assets.19 * @see https://developers.cloudflare.com/workers/static-assets/20 * Cloudflare Static Assets is currently in open beta. If this doesn't work for you,21 * please consider using Cloudflare Pages. You can start to create the Cloudflare Pages22 * application with the `npm create hono@latest` command.23 */24export const serveStatic = <E extends Env = Env>(25 options: ServeStaticOptions<E> = {}26): MiddlewareHandler => {27 return async function serveStatic(c, next) {28 const getContent = async (path: string) => {29 return getContentFromKVAsset(path, {30 manifest: options.manifest,31 // eslint-disable-next-line @typescript-eslint/ban-ts-comment32 // @ts-ignore33 namespace: options.namespace34 ? options.namespace35 : c.env36 ? c.env.__STATIC_CONTENT37 : undefined,38 })39 }40 return baseServeStatic({41 ...options,42 getContent,43 })(c, next)44 }45}