Skip to content

Commit

Permalink
Merge pull request #179 from sejori/hotfixes
Browse files Browse the repository at this point in the history
feat: async handlerGen in routesFromDir util
  • Loading branch information
sejori committed Aug 7, 2023
2 parents 5fd1130 + cec262c commit 20fffaf
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const mergeHeaders = (base: Headers, source: Headers) => {
* @param _depth: used internally to correct paths, don't set
* @returns routes: Route[]
*/
export const routesFromDir = async (dirUrl: URL, routeGen: (path: `/${string}`, url: URL) => Route, _depth = 1): Promise<Route[]> => {
export const routesFromDir = async (dirUrl: URL, routeGen: (path: `/${string}`, url: URL) => Promise<Route> | Route, _depth = 1): Promise<Route[]> => {
if (!(await Deno.stat(dirUrl)).isDirectory) throw new Error("URL does not point to directory.")
const routes: Route[] = []

Expand All @@ -37,7 +37,7 @@ export const routesFromDir = async (dirUrl: URL, routeGen: (path: `/${string}`,
for (let i=1; i<=_depth; i++) dirPath = `/${pieces[pieces.length-i]}${dirPath}`

const filePath: `/${string}` = `${dirPath}${file.name}`
routes.push(routeGen(filePath, fileUrl))
routes.push(await routeGen(filePath, fileUrl))
}
}

Expand Down

0 comments on commit 20fffaf

Please sign in to comment.