-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
44 lines (37 loc) · 989 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
40
41
42
43
44
var express = require('express');
var path = require('path');
var app = express();
// configure app
app.engine('html', require('ejs').renderFile);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// routes
if(process.env.NODE_ENV === 'production') {
app.use(express.static(path.join(__dirname, 'dist')));
} else {
app.use(express.static(path.join(__dirname, 'public')));
}
app.get('/', function(req, res) {
res.render('index');
});
app.get('/:route', function(req, res) {
if(req.params.route.split('.').length === 1) {
console.log('req.params.route', req.params.route);
res.render('index');
} else {
res.sendStatus(404);
}
});
// start
app.listen(process.env.PORT, function () {
console.log('Example app listening on port ' + process.env.PORT);
});
function _isAuthenticated(callback) {
return function(req, res, next) {
if(req.isAuthenticated()) {
callback(req, res, next);
} else {
next();
}
}
}