-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
67 lines (59 loc) · 1.98 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
66
67
/**
* Module dependencies.
*/
var express = require('express'),
routes = require('./src/routes'),
user = require('./src/routes/user'),
http = require('http'),
path = require('path'),
sql = require('mssql'),
bodyparser = require('body-parser'),
cookieParser = require('cookie-parser'),
session = require('express-session'),
passport = require('passport');
var common = {
'mongodbUrl' : 'mongodb://localhost:27017/libraryapp',
// 'mongodbUrl': 'mongodb://nodeexpress:T8bJfkGNqlnoqOIecShcnszBbxnGojch6Q2LA317mI6aykvnbEA3izT8Kq5YqSCe6hYK8OhhMJXSSD5rF0OkDg==@nodeexpress.documents.azure.com:10250/?ssl=true'
};
//sql based route task route
var taskRouter = require('./src/routes/taskrouter')();
//mongo db based route passing mongodb url
var adminRouter = require('./src/routes/adminrouter')(common);
var bookRouter = require('./src/routes/bookrouter')(common);
var authRouter = require('./src/routes/authrouter')(common);
var config = {
user: 'raunak2004',
password: 'Kelmai1986',
server: 'nodeexpressraunak.database.windows.net',
database: 'Task',
options: {
encrypt: true
}
};
sql.connect(config, function (err) {
console.log(err);
});
var app = express();
//config section
app.set('port', process.env.PORT || 3000);
//setting up views folder
app.set('views', './src/views');
app.set('view engine', 'ejs');
//checks body and creates req.body object
app.use(bodyparser.json());
app.use(bodyparser.urlencoded());
app.use(express.static(path.join(__dirname, 'public')));
app.use(cookieParser());
app.use(session({secret: 'library'}));
//require('./src/config/passport')(app);
//Individual routers
app.use('/tasks', taskRouter);
app.use('/admin', adminRouter);
app.use('/books', bookRouter);
app.use('/auth', authRouter);
app.get('/', routes.index);
app.get('/users', user.list);
//Start listening on server port
http.createServer(app).listen(app.get('port'), function () {
console.log("Express server listening on port " + app.get('port'));
});