utility/aliased/aliased_protocol.js
function respondInKind (opts = {}, callback) {
    let { req, res, responseData, err } = opts;
    opts.callback = (typeof opts.callback === 'function') ? opts.callback : callback;
    if ((path.extname(req.originalUrl) === '.html' || req.is('html') || req.is('text/html') || path.extname(req.originalUrl) === '.htm') || typeof opts.callback === 'function') {
      return this.protocol.respond(req, res, { data: responseData, err, return_response_data: true })
        .try(result => {
          if (typeof opts.callback === 'function') opts.callback(req, res, result);
          else return Promisie.resolve(result);
        })
        .catch(e => {
          if (typeof opts.callback === 'function') callback(e);
          else return Promisie.reject(e);
        });
    }
    else if (req.redirecturl) {
      req.redirectpath = (!req.redirectpath && req.redirecturl) ? req.redirecturl : req.redirectpath;
      return this.protocol.redirect(req, res);
    }
    else {
      let settings = (this.protocol && this.protocol.settings) ? this.protocol.settings : false;
      if (settings && settings.sessions && settings.sessions.enabled && req.session) req.flash = req.flash.bind(req);
      else req.flash = null;
      return this.protocol.respond(req, res, { data: responseData, err });
    }
  }
function respondInKind (opts = {}, callback) {
    let { req, res, responseData, err } = opts;
    opts.callback = (typeof opts.callback === 'function') ? opts.callback : callback;
    if ((path.extname(req.originalUrl) === '.html' || req.is('html') || req.is('text/html') || path.extname(req.originalUrl) === '.htm') || typeof opts.callback === 'function') {
      return this.protocol.respond(req, res, { data: responseData, err, return_response_data: true })
        .try(result => {
          if (typeof opts.callback === 'function') opts.callback(req, res, result);
          else return Promisie.resolve(result);
        })
        .catch(e => {
          if (typeof opts.callback === 'function') callback(e);
          else return Promisie.reject(e);
        });
    }
    else if (req.redirecturl) {
      req.redirectpath = (!req.redirectpath && req.redirecturl) ? req.redirecturl : req.redirectpath;
      return this.protocol.redirect(req, res);
    }
    else {
      let settings = (this.protocol && this.protocol.settings) ? this.protocol.settings : false;
      if (settings && settings.sessions && settings.sessions.enabled && req.session) req.flash = req.flash.bind(req);
      else req.flash = null;
      return this.protocol.respond(req, res, { data: responseData, err });
    }
  }
function respondInKind ( opts = { } , callback ) { let { req , res , responseData , err } = opts ; opts . callback = ( typeof opts . callback === 'function' ) ? opts . callback : callback ; if ( ( path . extname ( req . originalUrl ) === '.html' || req . is ( 'html' ) || req . is ( 'text/html' ) || path . extname ( req . originalUrl ) === '.htm' ) || typeof opts . callback === 'function' ) { return this . protocol . respond ( req , res , { data : responseData , err , return_response_data : true } ) . try ( result => { if ( typeof opts . callback === 'function' ) opts . callback ( req , res , result ) ; else return Promisie . resolve ( result ) ; } ) . catch ( e => { if ( typeof opts . callback === 'function' ) callback ( e ) ; else return Promisie . reject ( e ) ; } ) ; } else if ( req . redirecturl ) { req . redirectpath = ( ! req . redirectpath && req . redirecturl ) ? req . redirecturl : req . redirectpath ; return this . protocol . redirect ( req , res ) ; } else { let settings = ( this . protocol && this . protocol . settings ) ? this . protocol . settings : false ; if ( settings && settings . sessions && settings . sessions . enabled && req . session ) req . flash = req . flash . bind ( req ) ; else req . flash = null ; return this . protocol . respond ( req , res , { data : responseData , err } ) ; } }
Sends response data to client or returns formatted response data
@param  {Object}   opts     Configurable options (see periodicjs.core.protocols for more details)
@param {Function} opts.callback An optional callback. If this options is defined callback argument will be ignored
@param {*} opts.responseData Data to include in response object. If opts.err is defined this option will be ignored and the response will be treated as an error response
@param {*} opts.err Error data. If this option is defined response will always be an error response unless .ignore_error is true
@param {Object} opts.req Express request object
@param {Object} opts.res Express response object
@param  {Function} [callback] Optional callback function
@return {Function}         If callback is not defined optionally returns a Promise which will resolve response data
Sends response data to client or returns formatted response data