-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
41 lines (36 loc) · 990 Bytes
/
app.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
// app title
process.title = 'freeblog';
process.on('uncaughtException', function (err) {
console.error('uncaughtException', err.stack || err);
});
var express = require('express'),
routes = require('./routes'),
config = require('./config'),
host = config.host,
port = config.port,
publicDir = config.publicDir,
app = express();
app.set('views', config.viewDir);
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser(config.secret));
app.use(express.session());
// message
app.use(function (req, res, next) {
res.pushMessage = function (message) {
res.cookie('message', message, { httpOnly: false });
};
next();
});
// routes
routes(app);
// static
app.use(express.static(publicDir));
// listen on port
app.listen(port, host, function () {
console.log('server started');
console.log('http://%s:%d pid: %d', host, port, process.pid);
});