-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
98 lines (86 loc) · 2.85 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
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
'use strict';
Object.defineProperty(Array.prototype, 'indexOfObject', {
enumerable : false,
value : function(property, value) {
for ( var i = 0, len = this.length; i < len; i++) {
if (this[i][property] === value) {
return i;
}
}
return -1;
}
});
Array.prototype.splicePositiveIndex = function() {
if (arguments[0] < 0)
return null;
return Array.prototype.splice.apply(this, arguments);
};
// Module dependencies.
var express = require('express'), path = require('path');
var app = express();
var server = require('http').createServer(app);
require('./lib/services/socket').setIo(require('socket.io').listen(server));
var passport = require('./lib/services/authentication');
// Express Configuration
app.configure('development', function() {
app.use(require('connect-livereload')());
app.use(express.static(path.join(__dirname, '.tmp')));
app.use(express.static(path.join(__dirname, 'app')));
app.use(express.errorHandler());
app.set('views', __dirname + '/app/views');
});
app.configure('production', function() {
app.use(express.favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/views');
});
app.configure(function() {
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.cookieSession({
secret : 'ffoisaiods984'
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(express.methodOverride());
// prevent IE caching
app.use(function(req, res, next) {
res.header("Cache-Control", "no-cache, no-store, must-revalidate");
res.header("Pragma", "no-cache");
res.header("Expires", 0);
next();
});
// Router needs to be last
app.use(app.router);
});
// Controllers
var api = require('./lib/controllers/api'), controllers = require('./lib/controllers');
// Server Routes
app.get('/api/sites*', api.getSites);
app['delete']('/api/sites/*', api.deleteSite);
app.patch('/api/sites/*', api.updateSite);
app.post('/api/sites/?', api.createSite);
app.get('/api/users*', api.getUsers);
app['delete']('/api/users/*', api.deleteUser);
app.patch('/api/users/*', api.updateUser);
app.post('/api/users/?', api.createUser);
app.get('/api/cu*', api.getCurrentUser);
app.post('/api/login', api.login);
app.get('/logout*', function(req, res) {
req.logout();
res.redirect('/');
});
// Angular Routes
app.get('/partials/*', controllers.partials);
// form posting
app.all('/site/*', controllers.sendMail);
app.all('/*', passport.authenticationChain, controllers.index);
require('./lib/daos/journal');
// Start server
var port = process.env.PORT || 3000;
server.listen(port, function() {
console.log('Express server listening on port %d in %s mode', port, app.get('env'));
});