-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
27 lines (24 loc) · 958 Bytes
/
index.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 appRoute = require('./routes/appRoute')
const dashboardRoute = require('./routes/dashboardRoute')
const authRoute = require('./routes/authRoute')
const cookieParser = require('cookie-parser')
const { currentUser } = require('./middleware/authMiddleware')
require('dotenv').config({path: './config/config.env'})
const app = express()
mongoose.connect(process.env.MONGOODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
app.listen( process.env.PORT || 5000, () => console.log('Connected to server'))
}).catch(() => console.log('Failed connect to database'))
app.set('view engine', 'ejs')
app.use(express.static(__dirname + '/public'))
app.use(express.json())
app.use(cookieParser())
app.get('*', currentUser)
app.use(dashboardRoute)
app.use(appRoute)
app.use(authRoute)
app.get('*', (req, res) => res.render('404', { title: 'Page Not Found'}))