Skip to content

Instantly share code, notes, and snippets.

@SaulGarza
Created April 25, 2018 15:02
Show Gist options
  • Save SaulGarza/9595845b171c31a0764605e5e3feed29 to your computer and use it in GitHub Desktop.
Save SaulGarza/9595845b171c31a0764605e5e3feed29 to your computer and use it in GitHub Desktop.
//Assuming your file structure looks like below, you
//should be able to serve the index.html from server/app.js
//**************************************************//
//
// Project/
// server/
// app.js
// /* the rest of your backend */
// client/
// /* all client side files */
// dist/
// index.html
// bundle.js
// bundle.css
// /* whatever assets your build packaged */
//
//**************************************************//
//
// the only file in dist that you should be making yourself
// is dist/index.html, where you link the bundle.js and bundle.css
// files. usually through >_: create-react-app the command to build
// the bundle is `npm run build`, but you can check your package.json
// for extra help.
app.use('/', (req, res) => {
res.sendFile(path.join(__dirname, '../dist', 'index.html');
}
@SaulGarza
Copy link
Author

sidenote. dist stands for distribution. makes it a little easier to understand that the client code is not served, but instead the bundled styles and javascript is served to clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment