index.js
function servePage(bundle, opts) {
  opts = opts || {};

  if (typeof bundle !== 'function') {
    bundle = bundler.create(bundle, opts);
  }

  return function(req, res, next) {
    var location = makeLocation(req, opts.origin);
    var clientReq = request.createRequestFromLocation(location);
    bundle()
      .then(function(bundle) {
        return evaluatePromise({
          bundle: bundle,
          code: renderComponentToString(clientReq),
          debug: opts.debug,
          location: location
        });
      })
      .then(function(rendered) {
        var init = renderComponent(rendered.request.data);
        var markup = rendered.markup.replace(
          '</head>',
          '<script>' + init + '</script>'
        );
        res.setHeader('Content-type', 'text/html');
        res.statusCode = rendered.isNotFoundErrorHandled ? 404 : 200;
        res.write(markup);
        res.end();
      }, function(err) {
        err.isNotFoundError ? res.send(404) : next(err);
      });
  }
}
function servePage(bundle, opts) {
  opts = opts || {};

  if (typeof bundle !== 'function') {
    bundle = bundler.create(bundle, opts);
  }

  return function(req, res, next) {
    var location = makeLocation(req, opts.origin);
    var clientReq = request.createRequestFromLocation(location);
    bundle()
      .then(function(bundle) {
        return evaluatePromise({
          bundle: bundle,
          code: renderComponentToString(clientReq),
          debug: opts.debug,
          location: location
        });
      })
      .then(function(rendered) {
        var init = renderComponent(rendered.request.data);
        var markup = rendered.markup.replace(
          '</head>',
          '<script>' + init + '</script>'
        );
        res.setHeader('Content-type', 'text/html');
        res.statusCode = rendered.isNotFoundErrorHandled ? 404 : 200;
        res.write(markup);
        res.end();
      }, function(err) {
        err.isNotFoundError ? res.send(404) : next(err);
      });
  }
}
function servePage ( bundle , opts ) { opts = opts || { } ; if ( typeof bundle !== 'function' ) { bundle = bundler . create ( bundle , opts ) ; } return function ( req , res , next ) { var location = makeLocation ( req , opts . origin ) ; var clientReq = request . createRequestFromLocation ( location ) ; bundle ( ) . then ( function ( bundle ) { return evaluatePromise ( { bundle : bundle , code : renderComponentToString ( clientReq ) , debug : opts . debug , location : location } ) ; } ) . then ( function ( rendered ) { var init = renderComponent ( rendered . request . data ) ; var markup = rendered . markup . replace ( '</head>' , '<script>' + init + '</script>' ) ; res . setHeader ( 'Content-type' , 'text/html' ) ; res . statusCode = rendered . isNotFoundErrorHandled ? 404 : 200 ; res . write ( markup ) ; res . end ( ) ; } , function ( err ) { err . isNotFoundError ? res . send ( 404 ) : next ( err ) ; } ) ; } }
Middleware for serving pre-rendered React UI

@param {Bundler|Browserify|ModuleId} bundle
@param {Options} opts
Middleware for serving pre - rendered React UI