Created
November 13, 2018 15:09
-
-
Save achimoraites/20b3e7e1c4d796bb358d67738d9e53fb to your computer and use it in GitHub Desktop.
Simple Express Server to serve a react app located in client dir
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
const express = require('express'); | |
const app = express(); | |
// serve up production assets | |
app.use(express.static('client/build')); | |
// serve up the index.html if express does'nt recognize the route | |
const path = require('path'); | |
app.get('*', (req, res) => { | |
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html')); | |
}); | |
// if not in production use the port 5000 | |
const PORT = process.env.PORT || 5000; | |
console.log('server started on port:',PORT); | |
app.listen(PORT); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment