-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
35 lines (30 loc) · 1.02 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
const express=require('express');
const mongoose = require('mongoose');
const app = express();
const router = require('./routes/blogRoutes');
const authRoutes = require('./routes/authRoutes');
const cookieParser = require('cookie-parser');
const {requireAuth, checkUser } = require('./middleware/authMiddleware');
const user = require('./models/user.js');
const dbURI = 'mongodb+srv://kanodiakash:[email protected]/13Jun?retryWrites=true&w=majority&appName=KashMongo'
mongoose.connect(dbURI)
.then((result)=>app.listen(3000))
.catch((err)=>console.log(err));
app.set('view engine' ,'ejs');
app.use(express.static('public'));
app.use(express.json()); // AUTH
app.use(express.urlencoded({ extended: true }));
app.use(cookieParser());
app.get('*', checkUser);
app.get('/', (req, res) => {
res.redirect('/blogs');
});
app.get('/about', (req, res) => {
res.render('about');
});
app.use(router);
app.use(authRoutes);
// 404 page
app.use((req, res) => {
res.status(404).render('404');
});