-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.js
38 lines (24 loc) · 868 Bytes
/
app.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
var express = require('express'),
MongoClient = require('mongodb').MongoClient,
bodyParser = require('body-parser');
var db;
console.log('Starting up Thriftebook...');
var dbUrl = process.env.mongoDbUrl || 'mongodb://localhost:27017/thriftebook';
var app = express();
var port = process.env.PORT || 3000;
var dealsRouter;
app.use(bodyParser.urlencoded({extended:true}));
app.use(bodyParser.json());
app.use(express.static('./temp'));
MongoClient.connect(dbUrl, function(err, db) {
console.log("Connected correctly to MongoDb server at: " + dbUrl);
dealsRouter = require('./routes/dealRoutes')(db);
app.use('/api/deals', dealsRouter);
});
app.get('/', function(req, res){
res.send('Welcome to the Thriftebook API');
});
app.listen(port, function(){
console.log('Running Thriftebook on PORT: ' + port);
});
module.exports = app;