-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
67 lines (40 loc) · 1.58 KB
/
app.js
File metadata and controls
67 lines (40 loc) · 1.58 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require('body-parser')
const ejs = require("ejs")
const cookieParser = require("cookie-parser");
const storePostController = require('./controllers/storePostControl')
const PostController = require('./controllers/PostBlogControl')
const homeController = require('./controllers/indexBlog')
const getPostController = require('./controllers/getPostByIdControl')
const { checkUserData } = require("./middlewares/authenticate");
const authRoutes = require("./route/authentication");
// app constants
const { PORT, DATABASE } = require("./config");
// Initialize the application
const app = express()
// templating engine to access html flies
app.set('view engine', 'ejs')
// middleware for static flies
app.use(express.static('public'))
app.use(express.json());
app.use(cookieParser());
//initializing middleware to parser body
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))
app.use('/signup', authRoutes);
// Getting routes
app.get('/auth/register', (req, res) => {
res.render('register')
})
app.get('/auth/login', (req, res) => {
res.render('login')
})
app.get("/", homeController)
app.get("/post/:id", getPostController)
app.get("/posts/new", checkUserData, PostController)
app.post("/posts/store", storePostController)
// database connection
mongoose.connect(DATABASE, { useNewUrlParser: true, useUnifiedTopology: true })
//Listenting for the server on PORT
app.listen(PORT, () => { console.log(`Server successfully started on http://localhost:${PORT}`) })