-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
65 lines (49 loc) · 1.65 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
var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var session = require('express-session');
var passport = require('passport');
var mongoose = require('mongoose');
var MongoStore = require('connect-mongo')(session);
var uristring =
process.env.MONGOLAB_URI ||
process.env.MONGOHQ_URL ||
process.env.MONGODB_URI ||
'mongodb://localhost/codecoin';
// Makes connection asynchronously. Mongoose will queue up database
// operations and release them when the connection is complete.
mongoose.Promise = global.Promise;
mongoose.connect(uristring, { useMongoClient: true }, function (err, res) {
if (err) {
console.log ('ERROR connecting to: ' + uristring + '. ' + err);
} else {
console.log ('Succeeded connected to: ' + uristring);
}
});
var app = express();
// BodyParser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
// Express Session
app.use(session({
secret: 'UTXwa9iGRy',
saveUninitialized: true,
resave: true,
store: new MongoStore({mongooseConnection : mongoose.connection})
}));
var passportConfig = require('./config/passport')(app, passport);
app.get('/', function(req, res) {
return res.send("ok");
});
var user = require('./routes/user');
app.use('/user', user);
// The http server will listen to an appropriate port, or default to
// port 5000.
var thePort = process.env.PORT || 5000;
// Set Port
app.set('port', thePort);
app.listen(app.get('port'), function(){
console.log('Server started on port '+app.get('port'));
});