質問

だから、すべてが終わったと確信しているときにのみ「res.render」をしますよね?リクエストが終了し、ウェブページを撮影するからです。

役に立ちましたか?

解決

コールバックを提供しない場合 res.render(view[, options[, fn]]) 200 HTTPステータスとコンテンツタイプの200:Text/HTMLで自動的に応答します

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

Res.Render(view [、options [、fn]])

指定されたオプションとオプションのコールバックfnを使用してビューをレンダリングします。コールバック関数が与えられた場合、応答は自動的に行われませんが、それ以外の場合は200とテキスト/HTMLの応答が与えられます。

Express.jsガイド

他のヒント

電流で GitHubマスターコミット, 、 これは res.renderlib/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);
    }
  }
};
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top