-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
46 lines (37 loc) · 1.21 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
const express = require('express');
const mongoose = require('mongoose');
const ejs = require('ejs');
const path = require('path');
const postController = require('./controllers/postController');
const pageController = require('./controllers/pageController');
const methodOverride = require('method-override');
const app = express();
//CONNECT DATABASE
mongoose.connect('mongodb://localhost/cleanblog-test-db', {
useNewUrlParser: true,
useUnifiedTopology: true,
});
//TEMPLATE ENGINE
app.set('view engine', 'ejs');
//MIDDLEWARES
app.use(express.static('public'));
app.use(express.urlencoded({ extended: true }));
app.use(express.json());
app.use(
methodOverride('_method', {
methods: ['POST', 'GET'],
})
);
//ROUTES
app.get('/', pageController.getIndexPage);
app.get('/about', pageController.getAboutPage);
app.get('/posts/edit/:id', pageController.getEditPage);
app.get('/posts/:id', pageController.getPostPage);
app.get('/add_post', pageController.getAddPostPage);
app.delete('/posts/:id', postController.deletePost);
app.post('/posts', postController.createPost);
app.put('/posts/:id', postController.updatePost);
const port = 3000;
app.listen(port, () => {
console.log(`Sunucu ${port} portunda başlatıldı..`);
});