Skip to content

Commit

Permalink
feat: de-default loazy handles
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Nov 17, 2020
1 parent cb2a9ff commit 0cb8c0c
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ export function redirect (res: ResponseT, location: string, code = 302) {

export function lazy (handle: LazyHandle): Handle {
let _promise: Promise<Handle>
const resolve = () => (_promise = _promise || Promise.resolve(handle()))
const resolve = () => (
_promise = _promise ||
Promise.resolve(handle()).then((r: any) => r.default || r)
)
return function _lazy (req, res) {
return resolve().then(h => h(req, res))
}
Expand Down

0 comments on commit 0cb8c0c

Please sign in to comment.