-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
96 lines (57 loc) · 2.68 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const express = require('express')
const path = require('path')
const mongoose = require('mongoose')
const bodyParser = require('body-parser')
const exphbs = require('express-handlebars')
const routes = require('./src/routes/routes')
const passport = require('passport')
const localStrategy = require('./src/auth/local_strategy')
const expressSession = require('express-session')
const app = express()
const MONGO_URL = process.env.DATABASELOGIN
app.set('MONGO_URL', (process.env.MONGO_URL || MONGO_URL))
mongoose.connect(app.get('MONGO_URL'))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))
passport.use(localStrategy)
app.use(expressSession({
secret: 'keyboard_cat',
resave: true,
saveUninitialized: false,
}));
app.use(passport.initialize())
app.use(passport.session())
app.post('/admin/list',
passport.authenticate('local', { failureRedirect: '/error' }),
routes.authenticate, routes.list)
passport.serializeUser((user, done) => done(null, user))
passport.deserializeUser((user, done) => done(null, user))
app.engine('handlebars', exphbs({ defaultLayout: 'main' }))
app.set('view engine', 'handlebars')
app.set('port', (process.env.PORT || 3000))
app.use(express.static(path.join(`${__dirname}/public`)))
app.get('/', routes.index)
app.get('/admin', routes.admin)
app.get('/error', routes.error)
app.get('/admin/authorCourses/:id', routes.authenticate, routes.authorCourses)
app.get('/admin/contentList/:id', routes.authenticate, routes.contentList)
app.get('/admin/author/:id', routes.authenticate, routes.authorData)
app.get('/admin/newAuthor', routes.authenticate, routes.newAuthor)
app.get('/admin/list', routes.authenticate, routes.list)
app.post('/admin/saveAuthor', routes.authenticate, routes.saveAuthor)
app.get('/admin/course/:id', routes.authenticate, routes.courseData)
app.get('/admin/newCourse', routes.authenticate, routes.newCourse)
app.post('/admin/saveCourse', routes.authenticate, routes.saveCourse)
app.get('/insertCourse/:id', routes.authenticate, routes.insertCourse)
app.get('/content/:id', routes.content)
app.get('/course/:id', routes.course)
app.get('/author/:id', routes.author)
app.get('/admin/newContent/:id', routes.authenticate, routes.newContent)
app.post('/admin/saveContent/:courseId', routes.authenticate, routes.saveContent)
app.post('/admin/saveContent/edit/:contentId', routes.authenticate, routes.editContent)
app.get('/admin/content/:id', routes.authenticate, routes.contentData)
app.delete('/deleteItem/:id', routes.deleteItem)
app.get('/logout', routes.logoutSession)
app.use((req, res) => res.status(404).render('404'))
app.listen(app.get('port'), () =>
console.log(`Node app is running on port ${app.get('port')}`))