-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
51 lines (42 loc) · 1.38 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
var express = require('express')
,app = express()
,path = require('path')
,cookieParser = require('cookie-parser')
,bodyParser = require('body-parser')
,logger = require('morgan')
,session = require('express-session')
,mongoStore = require('connect-mongo')(session)
,passport = require('passport')
,mongoose = require('mongoose')
,http = require('http').Server(app)
,io = require('socket.io')(http)
,cors = require('cors');
app.use(cors());
mongoose.connect('mongodb://localhost/cardApp');
require('./models/models.js');
var db = mongoose.connection;
var socket = require('./routes/control')(io);
var auth = require('./routes/auth')(passport);
var api = require('./routes/api');
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(session({
secret: 'secretKey',
saveUninitialized: true,
cookie: { maxAge: 8*60*60*1000 },
resave: true,
store: new mongoStore({ url: 'mongodb://localhost/cardApp'})
}));
app.use(express.static(path.join(__dirname, 'public')));
app.use(passport.initialize());
app.use(passport.session());
var initPassport = require('./passport-init');
initPassport(passport);
app.use('/auth', auth);
app.use('/api', api);
var port = process.env.PORT || 3000;
http.listen(port, function() {
console.log("We are connected");
});