bin/server/sans-server.js
function request(server, config, hooks, keys, request, callback) {
    const start = Date.now();

    if (typeof request === 'function' && typeof callback !== 'function') {
        callback = request;
        request = {};
    }

    // handle argument variations and get Request instance
    const args = Array.from(arguments).slice(4).filter(v => v !== undefined);
    const req = (function() {
        const length = args.length;
        if (length === 0) {
            return new Request(server, keys, config.rejectable);

        } else if (length === 1 && typeof args[0] === 'function') {
            callback = args[0];
            return new Request(server, keys, config.rejectable);

        } else {
            return new Request(server, keys, config.rejectable, request);
        }
    })();

    // event log aggregation
    const queue = config.logs ? [] : null;
    if (queue) req.on('log', event => queue.push(event));

    // if logging enabled then produce the log when the request is fulfilled or rejected
    if (queue) {
        const log = function(state) {
            const events = queue.map((event, index) => {
                const seconds = util.seconds(event.timestamp - (index > 0 ? queue[index - 1].timestamp : start));
                return '[+' + seconds + 's] ' + event.category + ':' + event.type + ' ' + event.data;
            });
            console.log(state.statusCode + ' ' + req.method + ' ' + req.url +
                (state.statusCode === 302 ? '\n  Redirect To: ' + state.headers['location']  : '') +
                '\n  ID: ' + req.id +
                '\n  Start: ' + new Date(start).toISOString() +
                '\n  Duration: ' + prettyPrint.seconds(Date.now() - start) +
                '\n  Events:\n    ' +
                events.join('\n    '));
        };
        req.then(log, () => log(req.res.state));
    }

    // copy hooks into request
    req.log('initialized');
    Object.keys(hooks).forEach(type => {
        hooks[type].forEach(d => {
            req.hook(type, d.weight, d.hook)
        });
    });
    req.log('hooks applied');

    // is using a callback paradigm then execute the callback
    if (typeof callback === 'function') req.then(state => callback(null, state), err => callback(err, req.res.state));

    return req;
}
function request(server, config, hooks, keys, request, callback) {
    const start = Date.now();

    if (typeof request === 'function' && typeof callback !== 'function') {
        callback = request;
        request = {};
    }

    // handle argument variations and get Request instance
    const args = Array.from(arguments).slice(4).filter(v => v !== undefined);
    const req = (function() {
        const length = args.length;
        if (length === 0) {
            return new Request(server, keys, config.rejectable);

        } else if (length === 1 && typeof args[0] === 'function') {
            callback = args[0];
            return new Request(server, keys, config.rejectable);

        } else {
            return new Request(server, keys, config.rejectable, request);
        }
    })();

    // event log aggregation
    const queue = config.logs ? [] : null;
    if (queue) req.on('log', event => queue.push(event));

    // if logging enabled then produce the log when the request is fulfilled or rejected
    if (queue) {
        const log = function(state) {
            const events = queue.map((event, index) => {
                const seconds = util.seconds(event.timestamp - (index > 0 ? queue[index - 1].timestamp : start));
                return '[+' + seconds + 's] ' + event.category + ':' + event.type + ' ' + event.data;
            });
            console.log(state.statusCode + ' ' + req.method + ' ' + req.url +
                (state.statusCode === 302 ? '\n  Redirect To: ' + state.headers['location']  : '') +
                '\n  ID: ' + req.id +
                '\n  Start: ' + new Date(start).toISOString() +
                '\n  Duration: ' + prettyPrint.seconds(Date.now() - start) +
                '\n  Events:\n    ' +
                events.join('\n    '));
        };
        req.then(log, () => log(req.res.state));
    }

    // copy hooks into request
    req.log('initialized');
    Object.keys(hooks).forEach(type => {
        hooks[type].forEach(d => {
            req.hook(type, d.weight, d.hook)
        });
    });
    req.log('hooks applied');

    // is using a callback paradigm then execute the callback
    if (typeof callback === 'function') req.then(state => callback(null, state), err => callback(err, req.res.state));

    return req;
}
function request ( server , config , hooks , keys , request , callback ) { const start = Date . now ( ) ; if ( typeof request === 'function' && typeof callback !== 'function' ) { callback = request ; request = { } ; } // handle argument variations and get Request instance const args = Array . from ( arguments ) . slice ( 4 ) . filter ( v => v !== undefined ) ; const req = ( function ( ) { const length = args . length ; if ( length === 0 ) { return new Request ( server , keys , config . rejectable ) ; } else if ( length === 1 && typeof args [ 0 ] === 'function' ) { callback = args [ 0 ] ; return new Request ( server , keys , config . rejectable ) ; } else { return new Request ( server , keys , config . rejectable , request ) ; } } ) ( ) ; // event log aggregation const queue = config . logs ? [ ] : null ; if ( queue ) req . on ( 'log' , event => queue . push ( event ) ) ; // if logging enabled then produce the log when the request is fulfilled or rejected if ( queue ) { const log = function ( state ) { const events = queue . map ( ( event , index ) => { const seconds = util . seconds ( event . timestamp - ( index > 0 ? queue [ index - 1 ] . timestamp : start ) ) ; return '[+' + seconds + 's] ' + event . category + ':' + event . type + ' ' + event . data ; } ) ; console . log ( state . statusCode + ' ' + req . method + ' ' + req . url + ( state . statusCode === 302 ? '\n  Redirect To: ' + state . headers [ 'location' ] : '' ) + '\n  ID: ' + req . id + '\n  Start: ' + new Date ( start ) . toISOString ( ) + '\n  Duration: ' + prettyPrint . seconds ( Date . now ( ) - start ) + '\n  Events:\n    ' + events . join ( '\n    ' ) ) ; } ; req . then ( log , ( ) => log ( req . res . state ) ) ; } // copy hooks into request req . log ( 'initialized' ) ; Object . keys ( hooks ) . forEach ( type => { hooks [ type ] . forEach ( d => { req . hook ( type , d . weight , d . hook ) } ) ; } ) ; req . log ( 'hooks applied' ) ; // is using a callback paradigm then execute the callback if ( typeof callback === 'function' ) req . then ( state => callback ( null , state ) , err => callback ( err , req . res . state ) ) ; return req ; }
Get a request started.
@param {SansServer} server
@param {object} config
@param {object} hooks
@param {object} keys
@param {object} [request]
@param {function} [callback]
Get a request started .