-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
48 lines (40 loc) · 1.44 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
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var port = process.env.PORT || 8080;
var morgan = require('morgan');
var mongoose = require('mongoose');
const mongodburl = 'mongodb://localhost:27017/tutorial'
var router = express.Router();
var appRoutes = require('./app/routes/api')(router);
var path = require('path');
var passport = require('passport');
var social = require('./app/passport/passport')(app, passport);
//Following order is important
app.use(morgan('dev')); //Logs the requests
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(express.static(__dirname + '/public')); //access to front end files
//Backend routes url looks like http://localhost:8080/api/
app.use('/api', appRoutes);//Use routes
mongoose.connect(mongodburl, {useMongoClient: true}, function(err){
if(err){
console.log('Unable to connect to DB:' +err);
}else{
console.log('Successfully to connect to DB:');
}
});
/*
app.get('/home', function(req, res){
res.send("Hello Home");
})
app.get('/', function(req,res){
res.send('Hello');
});
*/
app.get('*', function(req,res){
res.sendFile(path.join(__dirname + '/public/app/views/index.html'));
})
app.listen(port, function(){
console.log('Server Running on port:'+port);
});