From 60e85b31cf1024e27a2d6421041d279e0f3db305 Mon Sep 17 00:00:00 2001 From: Yasha <85296952+the-pesar@users.noreply.github.com> Date: Mon, 29 Jan 2024 22:21:00 +0330 Subject: [PATCH] fix(bun): replace fs.existsSync() with Bun.file().exists() (#2115) --- src/adapter/bun/serve-static.ts | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/adapter/bun/serve-static.ts b/src/adapter/bun/serve-static.ts index 77946c8ae..6b017789b 100644 --- a/src/adapter/bun/serve-static.ts +++ b/src/adapter/bun/serve-static.ts @@ -1,14 +1,10 @@ // @denoify-ignore /* eslint-disable @typescript-eslint/ban-ts-comment */ -import { existsSync } from 'fs' import type { Context } from '../../context' import type { Env, MiddlewareHandler } from '../../types' import { getFilePath } from '../../utils/filepath' import { getMimeType } from '../../utils/mime' -// @ts-ignore -const { file } = Bun - export type ServeStaticOptions = { root?: string path?: string @@ -42,16 +38,16 @@ export const serveStatic = ( path = `./${path}` - if (existsSync(path)) { - const content = file(path) - if (content) { - const mimeType = getMimeType(path) - if (mimeType) { - c.header('Content-Type', mimeType) - } - // Return Response object - return c.body(content) + // @ts-ignore + const file = Bun.file(path) + const isExists = await file.exists() + if (isExists) { + const mimeType = getMimeType(path) + if (mimeType) { + c.header('Content-Type', mimeType) } + // Return Response object + return c.body(file) } await options.onNotFound?.(path, c)