UNPKG

waibu

Version:

Web Framework for Bajo

20 lines (18 loc) 564 B
async function mergeRouteHooks (def, withHandler = true) { const { last, isFunction } = this.lib._ const { hookTypes } = this.app.waibu const hooks = [...hookTypes] const me = this if (withHandler) hooks.push('handler') for (const h of hooks) { const oldH = def[h] if (!oldH) continue def[h] = async function (...args) { // TODO: hooks can be array of functions if (isFunction(last(args))) args.pop() args.push(this) return await oldH.call(me, ...args) } } } export default mergeRouteHooks