forked from benkaiser/stretto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
77 lines (63 loc) · 2.01 KB
/
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
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
/**
* Module dependencies.
*/
var express = require('express.oi');
var favicon = require('serve-favicon');
var bodyParser = require('body-parser');
var cookieParser = require('cookie-parser');
var errorhandler = require('errorhandler');
var http = require('http');
var path = require('path');
var util = require(__dirname + '/util.js');
var mkdirp = require('mkdirp');
var proxy = require('express-http-proxy');
var app = express().http().io();
var sessionOpts = {
secret: 'nmpsecret',
resave: true,
saveUninitialized: true,
};
app.io.session(sessionOpts);
app.io.set('authorization', function(handshakeData, accept) {
// accept all requests
accept(null, true);
});
// fetch the config directory
app.set('configDir', process.env.configDir || __dirname);
// make sure the dbs directory is present
mkdirp(app.get('configDir') + '/dbs/covers', function() {
// attach the db to the app
require(__dirname + '/db.js')(app);
// patch the app
require(__dirname + '/patches.js')(app);
// attach the config
app.set('config', require(__dirname + '/config')(app));
});
// all environments
app.set('port', process.env.PORT || 2000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.set('root', __dirname);
app.set('started', Date.now());
app.engine('html', require('swig').renderFile);
app.use(favicon(__dirname + '/static/images/favicon.ico'));
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.use(cookieParser());
app.use(express.session(sessionOpts));
app.use('/static', express.static(__dirname + '/static'));
// proxy for itunes requests
app.use('/proxy', proxy('https://itunes.apple.com', {
forwardPath: function(req, res) {
return require('url').parse(req.url).path;
},
}));
// development only
if (app.get('env') == 'development') {
app.use(errorhandler());
}
require(__dirname + '/routes').createRoutes(app);
app.listen(app.get('port'), function() {
console.log('Express server listening on port ' + app.get('port'));
});
module.exports = app;