-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
45 lines (45 loc) · 1.44 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
(function() {
var Settings, app, compileTemplate, express, fs, indexFilePath, path, settings, templates, _;
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
express = require('express');
path = require('path');
_ = require('underscore');
Settings = require('settings');
templates = {};
settings = new Settings(path.join(__dirname, 'config/environment.js')).getEnvironment();
fs = require('fs');
indexFilePath = 'templates/index.html';
compileTemplate = function(file) {
var templateName;
templateName = path.basename(file, path.extname(file));
return fs.readFile(file, 'utf8', __bind(function(err, data) {
var compiled;
if (err) {
return console.log(err);
}
compiled = _.template(data);
return templates[templateName] = compiled;
}, this));
};
compileTemplate(indexFilePath);
app = express.createServer();
app.configure(function() {
app.use(express.errorHandler(settings.errorHandling));
app.use(express.static(settings.publicDir, {
maxAge: settings.staticMaxAge
}));
app.use(express.bodyParser());
app.use(express.cookieParser({
maxAge: settings.cookieMaxAge
}));
return app.use(express.session({
secret: settings.cookieSecret
}));
});
app.get('/', function(req, res) {
return res.send(templates['index']({
name: 'World'
}));
});
app.listen(process.env.PORT || 8001);
}).call(this);