Skip to content

Commit

Permalink
feat: allow to use serve-static builder
Browse files Browse the repository at this point in the history
  • Loading branch information
cometkim committed Apr 16, 2024
1 parent 13c3156 commit ea5da5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 8 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@
"import": "./dist/helper/factory/index.js",
"require": "./dist/cjs/helper/factory/index.js"
},
"./base-serve-static": {
"types": "./dist/types/middlware/serve-static/index.d.ts",
"import": "./dist/middlware/serve-static/index.js",
"require": "./dist/cjs/middlware/serve-static/index.js"
},
"./cloudflare-workers": {
"types": "./dist/types/adapter/cloudflare-workers/index.d.ts",
"import": "./dist/adapter/cloudflare-workers/index.js",
Expand Down Expand Up @@ -475,6 +480,9 @@
"factory": [
"./dist/types/helper/factory/index.d.ts"
],
"base-serve-static": [
"./dist/types/middlware/serve-static"
],
"cloudflare-workers": [
"./dist/types/adapter/cloudflare-workers"
],
Expand Down
6 changes: 3 additions & 3 deletions src/middleware/serve-static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const defaultPathResolve = (path: string) => path
export const serveStatic = <E extends Env = Env>(
options: ServeStaticOptions<E> & {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
getContent: (path: string) => any
getContent: (path: string, c: Context<E>) => any
pathResolve?: (path: string) => string
}
): MiddlewareHandler => {
Expand Down Expand Up @@ -50,7 +50,7 @@ export const serveStatic = <E extends Env = Env>(
const pathResolve = options.pathResolve ?? defaultPathResolve

path = pathResolve(path)
let content = await getContent(path)
let content = await getContent(path, c)

if (!content) {
let pathWithOutDefaultDocument = getFilePathWithoutDefaultDocument({
Expand All @@ -61,7 +61,7 @@ export const serveStatic = <E extends Env = Env>(
return await next()
}
pathWithOutDefaultDocument = pathResolve(pathWithOutDefaultDocument)
content = await getContent(pathWithOutDefaultDocument)
content = await getContent(pathWithOutDefaultDocument, c)
if (content) {
path = pathWithOutDefaultDocument
}
Expand Down

0 comments on commit ea5da5a

Please sign in to comment.