-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
36 lines (24 loc) · 924 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
const express = require('express')
const bodyParser = require('body-parser')
const mongoose = require('mongoose')
mongoose.Promise = global.Promise
const authRouter = require('./routes/auth')
const adminSectionRouter = require('./routes/admin')
const PORT = 3000
const app = express()
app.locals.moment = require('moment')
app.set('view engine', 'pug')
app.use( express.static('public') )
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
const url = 'mongodb://localhost:27017/test'
mongoose.connect(url)
app.get('/about', (req,res) => res.send('this is about page') )
app.get('/', (req,res) => res.json(req.user) )
function isLoggedIn(req, res, next) {
if (req.isAuthenticated()) return next();
res.redirect('/login');
}
app.use( authRouter )
app.use( '/admin', isLoggedIn, adminSectionRouter )
app.listen(PORT, () => console.log(`🚀 Magic happens on PORT ${PORT}...`))