-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
113 lines (93 loc) · 2.84 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require("newrelic");
var config = require("./config.json");
var express = require("express");
var MongoStore = require('connect-mongo')(express);
var passport = require("passport");
var GoogleStrategy = require("passport-google-oauth").OAuth2Strategy;
var DB = require("./db.js");
var Routes = require("./routes.js");
var Plans = require("./plans.js");
var Users = require("./users.js");
var Scheduler = require("./scheduler.js");
var app = express();
var baseURLs =
{
"LOCAL": "http://127.0.0.1:5000",
"DEV": "http://contingencyplan.herokuapp.com"
};
config.server.env = process.env.ENV || "LOCAL";
config.server.port = process.env.PORT || config.server.port;
config.server.public_dir = process.env.PUBLIC_DIR || config.server.public_dir;
function startServer(db)
{
app.controllers =
{
plans: new Plans(db),
users: new Users(db)
};
// Instantiate and initialize App Routes
new Scheduler(db).loadJobsFromDB();
app.configure(function()
{
app.engine('.html', require('ejs').__express);
app.set("view engine", "html");
app.set('views', __dirname + '/views');
app.use(express.cookieParser());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.session(
{
secret: "crazy secret passphrase to make my cookie secure",
cookie:
{
maxAge: 2629740000
},
store: new MongoStore({ db: db })
}));
app.use(express.favicon());
app.use(express.logger("dev"));
app.use(passport.initialize());
app.use(passport.session());
new Routes(app);
app.use(app.router);
app.use(express["static"](config.server.public_dir));
});
app.configure("development", function()
{
app.use(express.errorHandler(
{
dumpException: true,
showStack: true
}));
});
passport.serializeUser(function(user, done)
{
done(null, user._id);
});
passport.deserializeUser(function(id, done)
{
app.controllers.users.findOne(id).then(function (user)
{
done(null, user);
}, function(err)
{
done(err, null);
});
});
passport.use(new GoogleStrategy(
{
clientID: "856641313075.apps.googleusercontent.com",
clientSecret: "fVFd03XmjNr8jNgGy-zPmYqG",
callbackURL: baseURLs[config.server.env] + "/auth/google/return"
},
function(accessToken, refreshToken, profile, done)
{
app.controllers.users.findByGoogleProfileOrCreate(profile).done(function(user)
{
done(null, user);
});
}));
app.listen(config.server.port);
console.log("App successfully initialized and started...");
}
DB.initialize().done(startServer);