Skip to content

Commit f8268e6

Browse files
committed
Set up web server
1 parent fd8ed60 commit f8268e6

File tree

3 files changed

+49
-60
lines changed

3 files changed

+49
-60
lines changed

package-lock.json

Lines changed: 22 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"dependencies": {
6+
"express": "^4.17.1",
67
"react": "^16.12.0",
78
"react-dom": "^16.12.0",
89
"react-scripts": "3.2.0"

server.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var express = require('express');
2+
var fs = require('fs');
3+
4+
var app = express();
5+
6+
var isProduction = process.env.NODE_ENV === 'production';
7+
var port = isProduction ? process.env.PORT : 4000;
8+
9+
app.use(express.static(__dirname + '/build'));
10+
11+
app.get('*', function (req, res, next) {
12+
// Prevents an HTML response for API calls
13+
if (req.path.indexOf('/api/') != -1) {
14+
return next();
15+
}
16+
17+
fs.readFile(__dirname + '/build/index.html', 'utf8', function (err, text) {
18+
res.send(text);
19+
20+
});
21+
});
22+
23+
app.listen(port, function () {
24+
console.log('SetLife-ReactWithApi: Server running on port ' + port);
25+
26+
});

0 commit comments

Comments
 (0)