Skip to content

Commit

Permalink
fix(bun): replace fs.existsSync() with Bun.file().exists() (#2115)
Browse files Browse the repository at this point in the history
  • Loading branch information
the-pesar authored Jan 29, 2024
1 parent f616ed9 commit 60e85b3
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/adapter/bun/serve-static.ts
Original file line number Diff line number Diff line change
@@ -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<E extends Env = Env> = {
root?: string
path?: string
Expand Down Expand Up @@ -42,16 +38,16 @@ export const serveStatic = <E extends Env = Env>(

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)
Expand Down

0 comments on commit 60e85b3

Please sign in to comment.