Skip to content

Commit

Permalink
src/open router handler for user.
Browse files Browse the repository at this point in the history
  • Loading branch information
bshy522 committed Sep 8, 2016
1 parent 048860a commit 6469f0f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/server/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import baseConfig from './config/webpack.config';
import loadConfig from './config';
import getIndexHtml from './index.html';
import getIframeHtml from './iframe.html';
import { getHeadHtml } from './utils';
import { getHeadHtml, getMiddleware } from './utils';

export default function (configDir) {
// Build the webpack configuration using the `baseConfig`
// custom `.babelrc` file and `webpack.config.js` files
const config = loadConfig('DEVELOPMENT', baseConfig, configDir);
const middlewareFn = getMiddleware(configDir);

// remove the leading '/'
let publicPath = config.output.publicPath;
Expand All @@ -30,6 +31,8 @@ export default function (configDir) {
router.use(webpackDevMiddleware(compiler, devMiddlewareOptions));
router.use(webpackHotMiddleware(compiler));

middlewareFn(router);

router.get('/', function (req, res) {
res.send(getIndexHtml(publicPath));
});
Expand Down
12 changes: 12 additions & 0 deletions src/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,15 @@ export function getEnvConfig(program, configEnv) {
}
});
}

export function getMiddleware(configDir) {
const middlewarePath = path.resolve(configDir, 'middleware.js');
if (fs.existsSync(middlewarePath)) {
let middlewareModule = require(middlewarePath); // eslint-disable-line global-require
if (middlewareModule.__esModule) {
middlewareModule = middlewareModule.default;
}
return middlewareModule;
}
return function () {};
}

0 comments on commit 6469f0f

Please sign in to comment.