Skip to content

Commit

Permalink
[BUGFIX] - hot reloading in development
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelBenin committed Apr 28, 2017
1 parent 580fde6 commit 1ef3f89
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 41 deletions.
5 changes: 5 additions & 0 deletions gulpfile.babel.js/configs/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ module.exports = {
filename: 'bundle.js',
publicPath: 'http://localhost:3001/static'
},
devServer: {
headers: {
'Access-Control-Allow-Origin': '*'
}
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
Expand Down
5 changes: 4 additions & 1 deletion gulpfile.babel.js/tasks/gulp_webpack_dev_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ gulp.task('webpack-dev-server', function runWebpackDevServer(callback) {
const webpackApp = new WebpackDevServer(webpack(config), {
publicPath: config.output.publicPath,
hot: true,
historyApiFallback: true
historyApiFallback: true,
headers: {
'Access-Control-Allow-Origin': '*'
}
});

const server = webpackApp.listen(3001, 'localhost',
Expand Down
66 changes: 33 additions & 33 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-ssr-spa",
"private": false,
"version": "6.0.0",
"version": "7.0.0",
"description": "Simple server rendered single page app.",
"repository": "https://github.com/michaelBenin/react-ssr-spa",
"license": "MIT",
Expand Down Expand Up @@ -78,7 +78,7 @@
"require-dir": "0.3.1",
"response-time": "2.3.2",
"scriptjs": "2.5.8",
"source-map-support": "0.4.14",
"source-map-support": "0.4.15",
"statuses": "1.3.1",
"striptags": "3.0.1",
"uuid": "3.0.1",
Expand Down
9 changes: 6 additions & 3 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ render(
);

if (module.hot) {
module.hot.accept(() => {
const HotLoadRoot = require('../views/containers/root_container'); // eslint-disable-line global-require
module.hot.accept([
'../react_router/react_router',
'../views/containers/root_container'
], () => {
const HotLoadRoot = require('../views/containers/root_container').default; // eslint-disable-line global-require
render(
<HotLoadRoot />,
<HotLoadRoot store={store} history={browserHistory} />,
window.document
);
});
Expand Down
3 changes: 2 additions & 1 deletion src/server/middleware/react_router_middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export default (req, res) => {

// TODO: cache rendered dom in redis
res.writeHead(status, {
'Content-Type': 'text/html'
'Content-Type': 'text/html',
'Access-Control-Allow-Origin': '*'
});

res.end(renderedDOM);
Expand Down
6 changes: 5 additions & 1 deletion src/views/containers/layouts/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ function mapStateToProps(state) {
}

Layout.propTypes = {
route: PropTypes.arrayOf(PropTypes.shape({})),
route: PropTypes.shape({
routes: PropTypes.arrayOf(PropTypes.shape({

}))
}),
env: PropTypes.string.isRequired,
staticUrl: PropTypes.string.isRequired
};
Expand Down

0 comments on commit 1ef3f89

Please sign in to comment.