Skip to content
This repository was archived by the owner on Oct 11, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions hyperion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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);

Expand Down
19 changes: 11 additions & 8 deletions hyperion/renderer/get-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'<script type="text/javascript" src="/./static/js/bootstrap.js"></script>',
''
)
.replace(/(src="\/static\/js\/main\.\w+?\.js")/g, ' defer="defer" $1');
return (
fs
.readFileSync(path.resolve(__dirname, '..', '..', 'build', 'index.html'))
.toString()
.replace(
'<script type="text/javascript" src="/./static/js/bootstrap.js"></script>',
''
)
// 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();
Expand Down