forked from johncruickshank/gin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
51 lines (44 loc) · 1.32 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
var express = require("express");
var app = express();
var bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(express.static("client/build"));
// app.use(require(".controllers/index"));
var ObjectId = require("mongodb").ObjectId;
var MongoClient = require("mongodb").MongoClient;
MongoClient.connect("mongodb://localhost:27017/gin_bars", function(err, client){
if(err){
return console.log(err);
}
db = client.db("gin_bars");
console.log("Connected to DB");
app.listen(3000, function () {
console.log("App running on port " + this.address().port);
});
});
app.get('/', function(req, res){
res.sendFile(__dirname + "client/build/index.html");
});
app.get("/bars", function(req, res){
db.collection("bars").find().toArray(function(err, results){
if(err){
return console.log(err);
}
res.json(results);
});
});
app.get("/bars/_id", function(req, res){
// req.body._id = new ObjectId(req.body._id);
db.collection("bars").find({ "_id": ObjectId("5a32aa64b40895f916cece55") }).toArray(function(err, results){
res.json(results);
});
});
app.get("/distilleries", function(req, res){
db.collection("distilleries").find().toArray(function(err, results){
if(err){
return console.log(err);
}
res.json(results);
});
});