forked from david2701/gomocha
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
55 lines (39 loc) · 1.47 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
var http = require('http');
var express = require('express');
var app = express();
var MongoClient = require('mongodb').MongoClient;
var mongoose = require('mongoose');
var getPrevsAndFavs = require('./routers/getPrevsAndFavs');
var orders = require('./routers/orders');
var ordersOrdersId = require('./routers/ordersOrdersId');
/* ------------------Mongoose--------------------- */
var MongoURI = process.env.NODE_ENV === 'production' ? process.env.MONGODB_URI : 'mongodb://amituuush:[email protected]:39327/gomocha'
mongoose.Promise = global.Promise;
mongoose.connect(MongoURI);
mongoose.connection.once('open', function() {
console.log('connection established!');
});
mongoose.connection.on('error', function(err) {
console.error('Could not connect. Error:', err);
});
/* -----------------Express------------------------ */
function customerRequestHandler(request, response) {
response.sendFile(__dirname + '/public/customer.html');
}
function BARequestHandler(request, response) {
response.sendFile(__dirname + '/public/business-admin.html');
}
app.use(express.static(__dirname + '/public'));
app.use('/api', getPrevsAndFavs);
app.use('/api', orders);
app.use('/api', ordersOrdersId);
app.get('/admin', BARequestHandler)
app.get('/', customerRequestHandler);
app.get('/*', (req, res) => {
res.redirect('/');
});
var log = function() {
console.log('app listening on port 4005');
}
app.listen(process.env.PORT || 4005, log);
module.exports = app;