Frage

Also, nur "res.render", wenn Sie sicher sind, dass alles fertig ist, oder? Weil es die Anfrage beendet und eine Webseite herausschreibt.

War es hilfreich?

Lösung

Wenn Sie keinen Rückruf angeben res.render(view[, options[, fn]]) Es gibt automatisch eine Antwort mit 200 HTTP-Status und Inhaltstyp: Text/HTML

res.render('view', {}, function() {
    while (true); // should block 
});

res.render (Ansicht [, Optionen [, fn]])

Rendernansicht mit den angegebenen Optionen und dem optionalen Rückruf Fn. Wenn eine Rückruffunktion angegeben wird, wird eine Antwort nicht automatisch durchgeführt, da ansonsten jedoch eine Antwort von 200 und Text/HTML angegeben werden.

Express.js Guide

Andere Tipps

Mit dem Strom Github Master Commit, das ist res.render in lib/view.js:

 /**
 * Render `view` with the given `options` and optional callback `fn`.
 * When a callback function is given a response will _not_ be made
 * automatically, however otherwise a response of _200_ and _text/html_ is given.
 *
 * Options:
 *  
 *  - `scope`     Template evaluation context (the value of `this`)
 *  - `debug`     Output debugging information
 *  - `status`    Response status code
 *
 * @param  {String} view
 * @param  {Object|Function} options or callback function
 * @param  {Function} fn
 * @api public
 */
res.render = function(view, opts, fn, parent, sub){
  // support callback function as second arg
  if ('function' == typeof opts) {
    fn = opts, opts = null;
  }

  try {
    return this._render(view, opts, fn, parent, sub);
  } catch (err) {
    // callback given
    if (fn) {
      fn(err);
    // unwind to root call to prevent
    // several next(err) calls
    } else if (sub) {
      throw err;
    // root template, next(err)
    } else {
      this.req.next(err);
    }
  }
};
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top