Skip to content

Commit

Permalink
feat(renderer): make renderer use bootstrapServer config
Browse files Browse the repository at this point in the history
Make renderer use an Express router and apply hopsConfig.bootstrapServer.

BREAKING CHANGE: createRenderer signature changed to options hash instead of discrete args
  • Loading branch information
dmbch committed Nov 14, 2017
1 parent 4437c6b commit ce2298d
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions packages/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@

var events = require('events');

var express = require('express');
var mocks = require('node-mocks-http');

var createMiddleware = require('hops-middleware');

module.exports = function createRenderer (webpackConfig, watchOptions) {
var middleware = createMiddleware(webpackConfig, watchOptions);
module.exports = function createRenderer (options) {
var hopsConfig = options.hopsConfig || {};
var router = new express.Router();

if (hopsConfig.bootstrapServer) {
hopsConfig.bootstrapServer(router, hopsConfig);
}

router.use(createMiddleware(
options.webpackConfig,
options.watchOptions
));

return function (location) {
return new Promise(function (resolve, reject) {
Expand All @@ -25,7 +36,7 @@ module.exports = function createRenderer (webpackConfig, watchOptions) {
resolve(res._getData());
}
});
middleware(req, res, function (error) {
router.handle(req, res, function (error) {
if (error) { reject(error); } else { resolve(); }
});
});
Expand Down

0 comments on commit ce2298d

Please sign in to comment.