-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
93 lines (71 loc) · 2.59 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* Module dependencies.
*/
var express = require('express');
var mongo = require("./libs/mongoExpressConnect");
var app = module.exports = express.createServer();
// Configuration
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', "*");
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
next();
}
var documentPaths = [
"./models/Achievement",
"./models/Phase",
"./models/Skill",
"./models/Team",
"./models/TeamMember"
];
app.configure('test', function(){
app.set("dbname", "SEED-test");
app.set("dbconnection", {host: "localhost", port: 27017});
mongo.drop(app);
app.use(mongo.connect(app,documentPaths));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('ede', function(){
app.set("dbname", "EDE-dev");
app.set("dbconnection", {host: "localhost", port: 27017});
mongo.drop(app);
app.use(mongo.connect(app,documentPaths));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('development', function(){
app.set("dbname", "SEED-dev");
app.set("dbconnection", {host: "localhost", port: 27017});
app.use(mongo.connect(app,documentPaths));
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
app.configure('production', function(){
app.set("dbname", "SEED-prod");
app.set("dbconnection", {host: "localhost", port: 27017});
app.use(mongo.connect(app,documentPaths));
app.use(express.errorHandler());
});
app.configure(function(){
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(allowCrossDomain);
app.use(app.router);
});
// Routes
require("./controllers/TeamMember").registerRoutes(app);
require("./controllers/Team").registerRoutes(app);
require("./controllers/Phase").registerRoutes(app);
var mongoCRUD = require("./libs/mongoCRUD");
var onUpdate = function(data, next) {
data.updatedAt = new Date();
next();
};
mongoCRUD(app, "Skill", mongo.createDefaults("Skill"), onUpdate);
mongoCRUD(app, "Team", mongo.createDefaults("Team"), onUpdate);
mongoCRUD(app, "TeamMember", mongo.createDefaults("TeamMember"), onUpdate);
mongoCRUD(app, "Phase", mongo.createDefaults("Phase"), onUpdate);
mongoCRUD(app, "Achievement", mongo.createDefaults("Achievement"), onUpdate);
app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
// global now and everyone accessible objects
now = require("now");
everyone = now.initialize(app);