forked from red-gold/react-social-network
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (28 loc) · 928 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var express = require('express');
var morgan = require('morgan');
var path = require('path');
// Create our app
var app = express();
const PORT = process.env.PORT || 3000;
// Setup logger
app.use(morgan(':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] :response-time ms'));
app.use(function (req, res, next){
if (req.headers['x-forwarded-proto'] === 'https') {
res.redirect('http://' + req.hostname + req.url);
} else {
next();
}
});
app.use(function(req, res, next) {
var userAgent = req.get('User-Agent');
console.log(userAgent);
next();
});
app.use(express.static('public'));
// Always return the main index.html, so react-router render the route in the client
app.get('*', (req, res) => {
res.sendFile(path.resolve('public', 'index.html'));
});
app.listen(PORT, function () {
console.log('Express server is up on port ' + PORT);
});