Question

Alors, que faire « res.render » lorsque vous êtes sûr que tout est fini, non? Parce qu'il met fin à la demande et sur les pousses d'une page Web.

Était-ce utile?

La solution

Si vous ne fournissez pas un rappel à res.render(view[, options[, fn]]) il donnera automatiquement une réponse avec 200 Status HTTP et Content-Type: text / html

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

res.render (vue [options [fn]])

Rendu de la vue avec les options disponibles et en option de rappel fn. Quand une fonction de rappel est donnée une réponse ne sera pas fait automatiquement, mais sinon une réponse de 200 et text / html est donné.

express.js guider

Autres conseils

Avec le courant github maître commit , c'est res.render dans 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);
    }
  }
};
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top