-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
66 lines (50 loc) · 1.84 KB
/
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
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
var express = require('express');
var mongoose = require('mongoose');
var bodyParser = require('body-parser');
var path = require('path');
//var port = 4200;
//var cors = require('cors');
// Mongoose connection with mongodb
mongoose.Promise = require('bluebird');
// mongodb://hugurlu:[email protected]:63918/reservations
//'mongodb://127.0.0.1/my_database'
mongoose.connect('mongodb://hugurlu:[email protected]:63918/reservations')
.then(() => { // if all is ok we will be here
console.log('Start');
})
.catch(err => { // if error we will be here
console.error('App starting error:', err.stack);
process.exit(1);
});
// Required application specific custom router module
var itemRouter = require('./src/routes/reservationRoutes');
// Use middlewares to set view engine and post json data to the server
//app.use(cors());
var app = express();
app.set('port', (process.env.PORT || 5000));
app.use(express.static(__dirname + '/public'));
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
// app.get('*', function(req, res) {
// res.sendFile(path.join(__dirname, '/public/index.html'));
// });
//Heroku get's confused with browser router vs express router
//Define specificly to use index.html
//it can be done more elegantly but time is limited
app.get('/add-item',function(req,res){
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.get('/search',function(req,res){
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.get('/index',function(req,res){
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.get('/edit/:id',function(req,res){
res.sendFile(path.join(__dirname, '/public/index.html'));
});
app.use('/reservations', itemRouter);
// Start the server
app.listen(app.get('port'), function(){
console.log('Server is running on Port: ', app.get('port'));
});