-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (32 loc) · 914 Bytes
/
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
const express=require('express');
const mongoose = require('mongoose');
const authRoutes= require('./routes/authRoutes')
const cookieParser = require('cookie-parser')
const {authenticated, checkUser} = require('./middleware/authmiddleware')
const app= express();
const User = require('./models/User')
app.set('view engine','ejs');
app.use(express.static('public'));
app.use(express.json());
app.use(authRoutes);
app.use(cookieParser());
const dotenv = require("dotenv");
dotenv.config();
app.get('/',checkUser, (req, res) =>
{res.render('home')}
);
app.get('/blogs', authenticated,(req, res) =>
res.render('blogs')
);
app.get('/new', authenticated,(req, res) =>
res.render('new')
);
const DB = process.env.DATABASE;
mongoose.connect(DB)
.then((result) => {
app.listen(3000)
console.log("Database connection successful!")
})
.catch((error) => {
console.log(error.message)
})