forked from B7Bprog/pocket-forest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (41 loc) · 1.17 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
const express = require("express");
const cors = require("cors");
const { PORT = 9090 } = process.env;
const monggose = require("mongoose");
const Tree = require("./models/tree");
const {
getAllTrees,
getTreeByID,
addTree,
addUser,
getAllUsers,
updateUser,
addUserImage,
addUserToTree,
} = require("./controllers/tree-controller");
const app = express();
const dbURI =
"mongodb+srv://pocketForest:[email protected]/pocket-forest?retryWrites=true&w=majority";
monggose
.connect(dbURI)
.then((response) => {
console.log("Connected to the database");
app.listen(PORT, (err) => {
if (err) throw err;
console.log(`Listening on ${PORT}...`);
});
})
.catch((err) => {
console.log(err);
});
app.use(cors());
app.use(express.json());
app.get("/api/all-trees", getAllTrees);
app.get("/api/trees/:tree_id", getTreeByID);
app.post("/api/add-tree", addTree);
app.post("/api/add-user", addUser);
app.get("/api/all-users", getAllUsers);
app.patch("/api/users/:username", updateUser);
app.patch("/api/trees/:tree_id/add-user-image", addUserImage);
app.patch("/api/trees/:tree_id/add-user", addUserToTree);
module.exports = app;