forked from tomgco/dis.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
64 lines (54 loc) · 1.98 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
/**
* Module dependencies.
*/
var express = require('express')
, properties = require('./properties')
, mongoDelegate = require('dis.io-mongo-crud')
, databaseAdaptor = mongoDelegate.database.createDatabaseAdaptor(properties.database)
, CrudDelegate = require('dis.io-mongo-crud').crud
, discovery = require('./lib/discovery')
, Routes = require('./routes')
, gzippo = require('gzippo')
, stylus = require('stylus')
, colors = require('colors')
, app = express.createServer()
;
app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.cookieParser());
app.use(express.session({ secret: "dis.troy" }));
app.use(express.bodyParser({
uploadDir: __dirname + '/uploads',
keepExtensions: true
}));
app.use(express.methodOverride());
app.use(stylus.middleware({ src: __dirname + '/public/', compress: true }));
app.use(gzippo.staticGzip(__dirname + '/public'));
app.use(app.router);
});
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
console.log('WARN: '.red + 'This application is running in development mode.'.yellow);
});
app.configure('production', function(){
app.use(express.errorHandler());
});
databaseAdaptor.createConnection(function(connection) {
var routes = Routes.createRoutes(app, connection)
;
setUpRoutes(routes);
app.listen(process.env.PORT || 3000);
console.log('http://' + app.address().address + ':' + app.address().port );
});
function setUpRoutes(routes) {
app.get('/', routes.get.index);
app.get('/distributors', routes.get.distributors);
app.get('/task', routes.get.task.listAll);
app.get('/task/view/:id', routes.get.task.view);
app.get('/task/stats/:id', routes.get.task.stats);
app.get('/task/edit/:id', routes.get.task.edit);
app.post('/task/update/:id', routes.post.task.update);
app.get('/task/create', routes.get.task.create);
app.post('/task/create', routes.post.task.create);
}