-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.js
52 lines (42 loc) · 1.68 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
var express = require('express'),
mongoose = require('mongoose'),
app = express(),
path = __dirname + '/views/',
bodyParser = require('body-parser'),
passport = require('passport'),
flash = require('connect-flash'),
secretKey = require('./secretKey.json'),
// router = require('./routes.js'),
session = require('express-session'),
APIrouter = require('./api.js'),
PGrouter = require('./PGroutes.js'),
bookRouter = require('./bookRoutes');
mongoose.connect(secretKey.key,{useMongoClient: true});
require('./config/passport.js')(passport); // pass passport for configuration
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({ extended: false })); // to support URL-encoded bodie
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("mLabs Connected! ");
});
app.set('port', (process.env.PORT || 3000));
app.use(express.static(__dirname + '/public'));
app.use('/playgrounds', express.static(__dirname + '/public'));
app.use('/book', express.static(__dirname + '/public'));
// views is directory for all template files
app.set('views', path);
app.set('view engine', 'ejs');
// the code ends here
//app.use(router);
app.use(session({ secret: 'ilovescotchscotchyscotchscotch' }));
app.use(passport.initialize());
app.use(passport.session()); // persistent login sessions
app.use(flash());
require('./Userroutes.js')(app, passport);
app.use('/playgrounds',PGrouter);
app.use('/book',bookRouter);
app.use('/api',APIrouter);
app.listen(app.get('port'), function() {
console.log('Node app is running on port', app.get('port'));
});