-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathweb-server.js
More file actions
71 lines (52 loc) · 1.81 KB
/
web-server.js
File metadata and controls
71 lines (52 loc) · 1.81 KB
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
69
70
71
/**
* Module dependencies
*/
var express = require('express');
var http = require('http');
var path = require('path');
var app = module.exports = express();
console.log("NODE_ENV: " + process.env.NODE_ENV);
// HOW TO SETUP SSL IN NODE: http://stackoverflow.com/questions/11567217/unable-to-setup-https-in-express-js
/**
* Configuration
*/
// all environments
app.set('port', process.env.PORT || 3003);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
if (process.env.NODE_ENV !== "staging" && process.env.NODE_ENV !== "production") {
// only use the *.less middleware when in developement
console.log("using less middleware");
app.use(require('less-middleware')({
dest: path.join(__dirname, 'public', 'app-build', 'css'),
src: path.join(__dirname, 'public', 'app-src', 'less'),
prefix: '/app-build/css',
force: true, // Always re-compile less files on each request.
compress: true
})); // needs to be declared before static middleware (in order to get the recompile working)
} else {
console.log("skipped less middleware");
}
app.use(express.static(path.join(__dirname, 'public')));
app.use(app.router);
// serve index and view partials
app.get('/debug', function (req, res) {
res.render('index_debug');
});
app.get('/', function (req, res) {
res.render('index');
});
app.get('/partials/:name', function (req, res) {
var name = req.params.name;
res.render('partials/' + name);
});
// only use this route if we want to show the "currently offline" site
// app.get('/*', function (req, res) {
// res.render('maintenance');
// });
http.createServer(app).listen(app.get('port'), function () {
console.log('Express server listening on port ' + app.get('port'));
});