forked from switowski/deploystack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
68 lines (57 loc) · 2.16 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
var express = require('express');
var path = require('path');
var logger = require('morgan');
var compression = require('compression');
var methodOverride = require('method-override');
var bodyParser = require('body-parser');
var expressValidator = require('express-validator');
// Controllers
var ContactController = require('./controllers/contact');
var HomeController = require('./controllers/home');
var app = express();
// Make env variables available in templates
app.locals.env = process.env;
// Make CDN URL available with =cdn in the pug templates
app.locals.cdn = process.env.CDN ? process.env.CDN : '';
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'pug');
app.set('port', process.env.PORT || 3000);
app.use(compression());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(expressValidator());
app.use(methodOverride('_method'));
// Static files
app.use(express.static(path.join(__dirname, 'public/css/bootstrap.min.css'), { maxAge: '1y'}));
app.use(express.static(path.join(__dirname, 'public/css/material-kit.min.css'), { maxAge: '30d'}));
app.use(express.static(path.join(__dirname, 'public/css/main.css'), { maxAge: '14d'}));
app.use(express.static(path.join(__dirname, 'public/js/main.min.js'), { maxAge: '14d'}));
app.use(express.static(path.join(__dirname, 'public')));
// Routing
app.get('/', HomeController.index);
app.get('/contact', ContactController.index);
// Add all sections (hosting, domains, etc.) to the routes in a loop
sections = HomeController.content;
Object.keys(sections).forEach(function(key) {
app.get(sections[key].url, function(req, res) {
res.render(key, {
content: sections[key],
title: sections[key].title
});
});
});
// Production settings
if (app.get('env') === 'production') {
// For production use port 8080
app.set('port', process.env.PORT || 8080);
// Production error handler
app.use(function(err, req, res, next) {
console.error(err.stack);
res.sendStatus(err.status || 500);
});
}
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
module.exports = app;