-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
70 lines (58 loc) · 1.97 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
require('newrelic');
var express = require('express')
, http = require('http')
, path = require('path')
, mongoose = require('mongoose')
, passport = require('passport')
, flash = require('connect-flash')
, configDB = require('./config/database.js')
, Users = require('./app/models/user');
var app = express();
mongoose.connect(configDB.url);
require('./config/passport.js')(passport); // pass passport for configuration
var QuestionSchema = new mongoose.Schema({
question: String,
answer:{
users:[{
loginName: String,
answer: String
}]
}
}),
Questions = mongoose.model('Questions', QuestionSchema);
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.cookieParser());
app.use(express.session({secret: 'cmsk3sle2i32lçcoe90ksd', cookie: {maxAge: 10800000 }}));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash()); // use connect-flash for flash messages stored in session
app.use(express.methodOverride());
app.use(app.router);
app.use(require('stylus').middleware(path.join(__dirname, 'public')));
app.use(express.static(path.join(__dirname, 'public')));
});
// =====================================
// ROUTES ==============================
// =====================================
/*
// non-www to www
app.all('*', function(req, res, next) {
if (req.headers.host.slice(0, 3) != 'www') {
res.redirect(301, 'http://www.' + req.headers.host + req.url);
} else {
next();
}
}); */
require('./app/routes.js')(app, passport, mongoose);
app.configure('development', function(){
app.use(express.errorHandler());
});
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
});