-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
103 lines (74 loc) · 2.24 KB
/
app.js
File metadata and controls
103 lines (74 loc) · 2.24 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
A sound aggregator.
Loïc Fontaine - http://github.com/lfont - MIT Licensed
*/
var express = require('express'),
ejsLocals = require('ejs-locals'),
routes = require('./routes'),
oauth = require('./lib/oauth'),
config = require('./lib/configuration');
var app = module.exports = express();
// configuration
app.configure('development', function () {
app.use(express.static(__dirname + '/public'));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
app.enable('verbose errors');
});
app.configure('production', function () {
app.use(express.static(__dirname + '/public-build'));
app.use(express.errorHandler());
app.disable('verbose errors');
});
app.configure(function () {
app.engine('ejs', ejsLocals);
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views');
app.use(express.favicon());
app.use(express.bodyParser());
app.use(express.cookieParser('secret string'));
app.use(express.session());
if (config.isAccessible) {
oauth.middleware(app); // before the router!!!
}
app.use(app.router);
});
// custom mime
express.static.mime.define({ 'application/x-web-app-manifest+json': [ 'webapp' ] });
express.static.mime.define({ 'text/cache-manifest': [ 'appcache' ] });
// default template data
app.locals({
appName : config.appName,
domain : config.domain,
trackingCode: config.google.trackingCode
});
// error handler
app.use(function (err, req, res, next) {
// we may use properties of the error object
// here and next(err) appropriately, or if
// we possibly recovered from the error, simply next().
res.status(err.status || 500);
res.render('error/500', {
title: 'Internal Error',
error: err
});
});
// routes
app.use(function (req, res) {
res.status(404);
// respond with html page
if (req.accepts('html')) {
res.render('error/404', {
title: 'Not Found',
url: req.url
});
return;
}
// respond with json
if (req.accepts('json')) {
res.send({ error: 'Not found' });
return;
}
// default to plain-text. send()
res.type('txt').send('Not found');
});
routes.register(app);