-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
49 lines (40 loc) · 1.49 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
const express = require("express")
const mongoose = require("mongoose")
const fileUpload = require("express-fileupload")
const methodOverride = require("method-override")
const ejs = require("ejs")
const photoController = require("./controllers/photoControllers")
const pageController = require("./controllers/pageController")
const app = express()
// // Connect DB
// mongoose.connect("mongodb://localhost/pcat-test-db")
mongoose.connect('mongodb+srv://atakan:FjTX6KC9s21IS42j@cluster0.llj5l.mongodb.net/pcat-db?retryWrites=true&w=majority').then(() => {
console.log("Connected to Database");
}).catch((err) => {
console.log("Not Connected to Database ERROR! ", err);
})
// TEMPLATE ENGINE
app.set("view engine", "ejs")
// MIDDLEWARES -> Everything between requests and responses.
app.use(express.static("public"))
app.use(express.urlencoded({ extended: true }))
app.use(express.json())
app.use(fileUpload())
app.use(
methodOverride("_method", {
methods: ["POST", "GET"],
})
)
// ROUTES
app.get("/", photoController.getAllPhotos)
app.get("/photos/:id", photoController.getPhoto)
app.post("/photos", photoController.createPhoto)
app.put("/photos/:id", photoController.updatePhoto)
app.delete("/photos/:id", photoController.deletePhoto)
app.get("/about", pageController.getAboutPage)
app.get("/add", pageController.getAddPage)
app.get("/photos/edit/:id", pageController.getEditPage)
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Server is started at port ${port}...`)
})