-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.js
63 lines (51 loc) · 1.62 KB
/
routes.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
const router = require('express').Router()
// Import controllers
import pages from './controllers/pages'
import configurations from './controllers/configurations'
import articles from './controllers/articles'
import members from './controllers/members'
import chats from './controllers/chats'
// Some middleware we run on all routes eg. storing session as local variable
router.use((req,res, next) => {
// get our configurations
configurations.get().then(configs => {
res.locals.currentTheme = configs['currentTheme']
res.locals.name = configs['siteName']
next()
})
// set local variable session
res.locals.session = req.session
// if member is logged in, set exported variable
if(req.session.member) {
exports.screenName = req.session.member.screenName
}
})
// Index route
router.get('/', (req, res) => {
res.render('index')
})
// Pages Routes
router.route('/pages')
.get(pages.get)
.post(pages.create)
router.get('/pages/new', pages.new)
// Articles Routes
router.route('/articles')
.get(articles.get)
.post(articles.create)
.put(articles.update)
.delete(articles.delete)
router.get('/articles/new', articles.new)
// Members Routes
router.post('/members', members.create)
router.post('/members/logout', members.logout)
router.post('/members/login', members.login)
router.get('/members/new', members.new)
// Chats Routes
router.get('/chats', chats.get)
// A catch-all redirect to the 404 template
router.all('*', (req, res) => {
res.status(404).render('modules/app/404', { reason: 'Page Not Found!' })
})
exports.router = router
exports.screenName = ''