bin/server/sans-server.js
function addHook(hooks, type, weight, hook) {
    const length = arguments.length;
    let start = 2;

    if (typeof type !== 'string') {
        const err = Error('Expected first parameter to be a string. Received: ' + type);
        err.code = 'ESHOOK';
        throw err;
    }

    // handle variable input parameters
    if (typeof arguments[2] === 'number') {
        start = 3;
    } else {
        weight = 0;
    }

    if (!hooks[type]) hooks[type] = [];
    const store = hooks[type];
    for (let i = start; i < length; i++) {
        const hook = arguments[i];
        if (typeof hook !== 'function') {
            const err = Error('Invalid hook specified. Expected a function. Received: ' + hook);
            err.code = 'ESHOOK';
            throw err;
        }
        store.push({ weight: weight, hook: hook });
    }

    return this;
}
function addHook(hooks, type, weight, hook) {
    const length = arguments.length;
    let start = 2;

    if (typeof type !== 'string') {
        const err = Error('Expected first parameter to be a string. Received: ' + type);
        err.code = 'ESHOOK';
        throw err;
    }

    // handle variable input parameters
    if (typeof arguments[2] === 'number') {
        start = 3;
    } else {
        weight = 0;
    }

    if (!hooks[type]) hooks[type] = [];
    const store = hooks[type];
    for (let i = start; i < length; i++) {
        const hook = arguments[i];
        if (typeof hook !== 'function') {
            const err = Error('Invalid hook specified. Expected a function. Received: ' + hook);
            err.code = 'ESHOOK';
            throw err;
        }
        store.push({ weight: weight, hook: hook });
    }

    return this;
}
function addHook ( hooks , type , weight , hook ) { const length = arguments . length ; let start = 2 ; if ( typeof type !== 'string' ) { const err = Error ( 'Expected first parameter to be a string. Received: ' + type ) ; err . code = 'ESHOOK' ; throw err ; } // handle variable input parameters if ( typeof arguments [ 2 ] === 'number' ) { start = 3 ; } else { weight = 0 ; } if ( ! hooks [ type ] ) hooks [ type ] = [ ] ; const store = hooks [ type ] ; for ( let i = start ; i < length ; i ++ ) { const hook = arguments [ i ] ; if ( typeof hook !== 'function' ) { const err = Error ( 'Invalid hook specified. Expected a function. Received: ' + hook ) ; err . code = 'ESHOOK' ; throw err ; } store . push ( { weight : weight , hook : hook } ) ; } return this ; }
Define a hook that is applied to all requests.
@param {object} hooks
@param {string} type
@param {number} [weight=0]
@param {...function} hook
@returns {SansServer}
Define a hook that is applied to all requests .