-
Notifications
You must be signed in to change notification settings - Fork 23
/
app.js
27 lines (22 loc) · 887 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
const express = require('express');
const mongoose = require('mongoose');
const authRoutes = require('./routes/auth')
const cookieParser = require('cookie-parser');
const app = express();
const { requireAuth } = require('./middleware/authMiddleware');
// middleware
app.use(express.static('public'));
app.use(express.json());
app.use(cookieParser())
// view engine
app.set('view engine', 'ejs');
// database connection
// const dbURI = 'mongodb+srv://aabiskar:test123@cluster0.3cnv3.mongodb.net/mern-login';
const dbURI = 'mongodb://localhost:27017/mern-login'
mongoose.connect(dbURI, { useNewUrlParser: true, useUnifiedTopology: true, useCreateIndex:true })
.then((result) => app.listen(3000))
.catch((err) => console.log(err));
// routes
app.get('/', (req, res) => res.render('home'));
app.get('/burgers', requireAuth, (req, res) => res.render('burgers'));
app.use(authRoutes)