-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (32 loc) · 1.12 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
if(process.env.NODE_ENV !== 'production'){
require('dotenv').config();
}
// Packages
const express = require('express');
const mongoose = require('mongoose');
const cookieParser = require('cookie-parser');
const { requireAuth, chcekUser } = require('./middleware/authMiddleware');
// Routers
const userRoute = require('./routes/userRoute');
const app = express();
// middleware
app.use(express.static('public'));
app.use(express.json());
app.use(express.urlencoded({extended:true}));
app.use(cookieParser());
// view engine
app.set('view engine', 'ejs');
// database connection
mongoose.connect(process.env.DB_URL, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => console.log("Connected to the database"))
.catch((err) => console.log(err));
// routes
app.get('*', chcekUser);
app.get('/', (req, res) => res.render('home'));
app.get('/smoothies', requireAuth, (req, res) => res.render('smoothies'));
app.use('/user', userRoute);
app.use( (req,res) => {
res.render('404');
});
// Listening to the port
app.listen(process.env.PORT || 3000, () => console.log('Server up and running!'));