Created
July 26, 2016 19:51
-
-
Save SIRHAMY/56744f867efc6c0616e55dcc87752f9b to your computer and use it in GitHub Desktop.
Example app.js to run react-router on a Node and Express web server
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
// This application uses express as its web server | |
// for more info, see: http://expressjs.com | |
var express = require('express'); | |
const path = require('path') | |
// create a new express server | |
var app = express(); | |
// serve the files out of ./public as our main files | |
app.use(express.static(__dirname + '/public')); | |
// This tells Express to send every request we get through index.html, | |
// allowing react-router to handle it | |
app.get('*', function (request, response){ | |
response.sendFile(path.resolve(__dirname, 'public', 'index.html')) | |
}); | |
// start server on the specified port and binding host | |
app.listen(appEnv.port, '0.0.0.0', function() { | |
// print a message when the server starts listening | |
console.log("server starting on " + appEnv.url); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment