diff --git a/hyperion/index.js b/hyperion/index.js
index 197be4bfab..13473ed7fe 100644
--- a/hyperion/index.js
+++ b/hyperion/index.js
@@ -60,6 +60,14 @@ app.use('/websocket', (req: express$Request, res: express$Response) => {
);
});
+// In development the Webpack HMR server requests /sockjs-node constantly,
+// so let's patch that through to it!
+if (process.env.NODE_ENV === 'development') {
+ app.use('/sockjs-node', (req: express$Request, res: express$Response) => {
+ res.redirect(301, `http://localhost:3000${req.path}`);
+ });
+}
+
import cookieParser from 'cookie-parser';
app.use(cookieParser());
@@ -95,6 +103,14 @@ app.use(
express.static(path.resolve(__dirname, '..', 'build'), { index: false })
);
+// In dev the static files from the root public folder aren't moved to the build folder by create-react-app
+// so we just tell Express to serve those too
+if (process.env.NODE_ENV === 'development') {
+ app.use(
+ express.static(path.resolve(__dirname, '..', 'public'), { index: false })
+ );
+}
+
import renderer from './renderer';
app.get('*', renderer);
diff --git a/hyperion/renderer/get-html.js b/hyperion/renderer/get-html.js
index 72b6cdcfcc..03242f3dfa 100644
--- a/hyperion/renderer/get-html.js
+++ b/hyperion/renderer/get-html.js
@@ -4,14 +4,17 @@ import path from 'path';
import serialize from 'serialize-javascript';
const getIndex = () => {
- return fs
- .readFileSync(path.resolve(__dirname, '..', '..', 'build', 'index.html'))
- .toString()
- .replace(
- '',
- ''
- )
- .replace(/(src="\/static\/js\/main\.\w+?\.js")/g, ' defer="defer" $1');
+ return (
+ fs
+ .readFileSync(path.resolve(__dirname, '..', '..', 'build', 'index.html'))
+ .toString()
+ .replace(
+ '',
+ ''
+ )
+ // This automatically gets injected without the defer tag in development by create-react-app, gotta get rid of it for dev to work!
+ .replace(/(src="\/static\/js\/bundle\.js")/g, ' defer="defer" $1')
+ );
};
let html = getIndex();