Created
April 8, 2018 06:46
-
-
Save reciosonny/7d52e01dc36dbe22bc98c06b38050a25 to your computer and use it in GitHub Desktop.
Code snippet for setting up react app inside node #nodejs #javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (process.env.NODE_ENV === 'production') { | |
| //Express will serve up production assets | |
| //like our main.js file, or main.css file | |
| app.use(express.static('client/build')); | |
| //Express will serve up the index.html file | |
| //if it doesn't recognize the route | |
| //note 1: if it doesn't recognize the file being scanned above(static/client/build), then it will go through here to find the index.html file. This route is a catch-all scenario just to load the client app in express server. | |
| const path = require('path'); | |
| app.get('*', (req, res) => { | |
| res.sendfile(path.resolve(__dirname, 'client', 'build', 'index.html')); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment