forked from jamesjackson/braveapp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
62 lines (51 loc) · 1.58 KB
/
index.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
var restify = require('restify');
var passport = require('passport');
var mongoose = require('mongoose');
var session = require('express-session');
var MongoStore = require('connect-mongo')(session);
var fs = require('fs');
require('./modules/config/passport')(passport);
var dbURL = process.env.MONGOHQ_URL;
function respond(req, res, next) {
res.send('hello ' + req.params.name);
next();
}
var server = restify.createServer();
server.get('/hello/:name', respond);
server.head('/hello/:name', respond);
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
mongoose.connect(dbURL); // connect to our database
mongoose.connection.on('error', function (err) {
console.log(err);
});
server.use(restify.CORS());
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(session({
key : 'SessionKey',
secret : 'CATONTHEKEYBOARD',
cookie : {
path : '/',
httpOnly : true,
maxAge : null
},
resave: true,
saveUninitialized: true,
store : new MongoStore({
url : dbURL,
collection : 'sessions',
stringify : false
}).on('connected', function(result) {
console.log('Connected to sessions db!');
return;
})
}));
server.use(passport.initialize());
server.use(passport.session());
require('./modules/config/routes.js')(server, restify, passport);
server.listen(process.env.PORT || 8080, function() {
return console.log('%s listening at %s', server.name, server.url);
});