christmas/routes/index.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-11-08 14:23:51 -08:00
const publicRoute = require('../middlewares/publicRoute')
2020-11-08 13:54:08 -08:00
const express = require('express')
const path = require('path')
2018-11-20 11:19:58 -08:00
2019-11-17 12:46:08 -08:00
module.exports = ({ db, config }) => {
2020-11-08 13:54:08 -08:00
const router = express.Router()
2018-11-20 11:19:58 -08:00
2020-11-08 13:54:08 -08:00
router.use('/', express.static(path.join(__dirname, '../static')))
2018-11-20 11:19:58 -08:00
router.get('/',
async (req, res, next) => {
2020-11-08 13:54:08 -08:00
const dbInfo = await db.info()
2018-11-20 11:19:58 -08:00
if (dbInfo.doc_count === 0) {
2020-11-08 13:54:08 -08:00
res.redirect('/setup')
2018-11-20 11:19:58 -08:00
} else {
2020-11-08 13:54:08 -08:00
next()
2018-11-20 11:19:58 -08:00
}
},
2020-11-08 14:23:51 -08:00
publicRoute(),
2018-11-20 11:19:58 -08:00
(req, res) => {
2020-11-08 13:54:08 -08:00
res.redirect('/wishlist')
2018-11-20 11:19:58 -08:00
}
2020-11-08 13:54:08 -08:00
)
2018-11-20 11:19:58 -08:00
2019-11-17 15:05:45 -08:00
router.use('/api', require('./api')({ db }))
2020-11-08 13:54:08 -08:00
router.use('/setup', require('./setup')(db))
2018-11-20 11:19:58 -08:00
2020-11-08 13:54:08 -08:00
router.use('/login', require('./login')())
router.use('/logout', require('./logout')())
router.use('/resetpw', require('./resetpw')(db))
router.use('/confirm-account', require('./confirm-account')(db))
2018-11-20 11:19:58 -08:00
2020-11-08 13:54:08 -08:00
router.use('/wishlist', require('./wishlist')(db))
2020-11-05 14:42:24 -08:00
router.use('/supported-sites', require('./supported-sites')())
2018-11-20 11:19:58 -08:00
2020-11-08 13:54:08 -08:00
router.use('/profile', require('./profile')(db))
2018-11-20 11:19:58 -08:00
2020-11-08 13:54:08 -08:00
router.use('/admin-settings', require('./adminSettings')(db))
2018-11-20 11:19:58 -08:00
2019-11-17 12:46:08 -08:00
router.use('/manifest.json', require('./manifest.json')({ config }))
2020-11-08 13:54:08 -08:00
return router
}