-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
45 lines (38 loc) · 1.41 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
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/pageControllers');
const app = express();
// Connect Db
mongoose.connect('mongodb+srv://nuray:UYAaWLrr3%23%237$te@cluster0.mxvqu.mongodb.net/photo-catalog?retryWrites=true&w=majority')
.then(() =>{
console.log('DB Connected!')
})
// TEMPLATE ENGINE
app.set('view engine', 'ejs');
// MIDDLEWARES
app.use(express.static('public'));
app.use(express.urlencoded({ extended: true })); // urlden gelen dataları alır.
app.use(express.json()); // dataları json yapısına çevirir.
app.use(fileUpload());
app.use(
methodOverride('_method', {
methods: ['POST', 'GET'],
})
);
// ROUTERING
app.get('/', photoController.getAllPhotos);
app.get('/photo/:id', photoController.getPhoto);
app.post('/photos', photoController.createPhoto);
app.put('/photo/:id', photoController.updatePhoto);
app.delete('/photo/:id', photoController.deletePhoto);
app.get('/about', pageController.getAboutPage);
app.get('/addPhoto', pageController.getAddPage);
app.get('/photo/edit/:id', pageController.getEditPage);
const port = process.env.PORT || 5000;
app.listen(port, () => {
console.log(`Sunucu port ${port} da çalışıyor.`);
});