lib/install.js
/**
 * using the restify handler composer, create a middleware on the fly that
 * re-requires the file on every load executes it.
 * @private
 * @function reloadProxy
 * @param {Object} opts an options object
 * @param {String} opts.basePath The basepath to resolve source files.
 * @param {String} opts.method http verb
 * @param {Object} opts.log the enroute logger
 * @param {Object} opts.req the request object
 * @param {Object} opts.res the response object
 * @param {String} opts.routeName the name of the restify route
 * @param {String} opts.sourceFile the response object
 * @param {Function} cb callback fn
 * @returns {undefined}
 */
using the restify handler composer, create a middleware on the fly that
re-requires the file on every load executes it.
@private
@function reloadProxy
@param {Object} opts an options object
@param {String} opts.basePath The basepath to resolve source files.
using the restify handler composer create a middleware on the fly that re - requires the file on every load executes it . @private @function reloadProxy @param { Object } opts an options object @param { String } opts . basePath The basepath to resolve source files .
function reloadProxy(opts, cb) {
    assert.object(opts, 'opts');
    assert.string(opts.basePath, 'opts.basePath');
    assert.optionalString(opts.excludePath, 'opts.excludePath');
    assert.string(opts.method, 'opts.method');
    assert.object(opts.req, 'opts.req');
    assert.object(opts.res, 'opts.res');
    assert.string(opts.routeName, 'opts.routeName');
    assert.string(opts.sourceFile, 'opts.sourceFile');
    assert.func(cb, 'cb');
    var excludeFullpath = opts.basePath + '/' + opts.excludePath;
    Object.keys(require.cache).forEach(function (cacheKey) {
        if (opts.excludePath && cacheKey.indexOf(excludeFullpath) !== -1) {
            return;
        } else if (cacheKey.indexOf(opts.basePath) !== -1) {
            delete require.cache[cacheKey];
        }
    });
    var handlers;
    try {
        handlers = require(opts.sourceFile);
    } catch (e) {
        var err = new verror.VError({
            name: 'EnrouteRequireError',
            cause: e,
            info: {
                file: opts.sourceFile,
                route: opts.routeName,
                method: opts.method
            }
        }, 'failed to require file, possible syntax error');
        return cb(err);
    }
    var handlerChain = compose(handlers);
    return handlerChain(opts.req, opts.res, cb);
}
function reloadProxy ( opts , cb ) { assert . object ( opts , 'opts' ) ; assert . string ( opts . basePath , 'opts.basePath' ) ; assert . optionalString ( opts . excludePath , 'opts.excludePath' ) ; assert . string ( opts . method , 'opts.method' ) ; assert . object ( opts . req , 'opts.req' ) ; assert . object ( opts . res , 'opts.res' ) ; assert . string ( opts . routeName , 'opts.routeName' ) ; assert . string ( opts . sourceFile , 'opts.sourceFile' ) ; assert . func ( cb , 'cb' ) ; var excludeFullpath = opts . basePath + '/' + opts . excludePath ; Object . keys ( require . cache ) . forEach ( function ( cacheKey ) { if ( opts . excludePath && cacheKey . indexOf ( excludeFullpath ) !== - 1 ) { return ; } else if ( cacheKey . indexOf ( opts . basePath ) !== - 1 ) { delete require . cache [ cacheKey ] ; } } ) ; var handlers ; try { handlers = require ( opts . sourceFile ) ; } catch ( e ) { var err = new verror . VError ( { name : 'EnrouteRequireError' , cause : e , info : { file : opts . sourceFile , route : opts . routeName , method : opts . method } } , 'failed to require file, possible syntax error' ) ; return cb ( err ) ; } var handlerChain = compose ( handlers ) ; return handlerChain ( opts . req , opts . res , cb ) ; }
using the restify handler composer, create a middleware on the fly that
 re-requires the file on every load executes it.
using the restify handler composer create a middleware on the fly that re - requires the file on every load executes it .
// clear require cache for code loaded from a specific base dir // now that the chain has failed, send back the require error. // if no require error, execute the handler chain. any errors that occur at // runtime should be a runtime exception.