mirror of https://github.com/requarks/wiki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.1 KiB
39 lines
1.1 KiB
5 years ago
|
const express = require('express')
|
||
|
const router = express.Router()
|
||
|
const _ = require('lodash')
|
||
5 years ago
|
const qs = require('querystring')
|
||
5 years ago
|
|
||
|
/* global WIKI */
|
||
|
|
||
|
/**
|
||
|
* Let's Encrypt Challenge
|
||
|
*/
|
||
|
router.get('/.well-known/acme-challenge/:token', (req, res, next) => {
|
||
|
res.type('text/plain')
|
||
|
if (_.get(WIKI.config, 'letsencrypt.challenge', false)) {
|
||
|
if (WIKI.config.letsencrypt.challenge.token === req.params.token) {
|
||
|
res.send(WIKI.config.letsencrypt.challenge.keyAuthorization)
|
||
|
WIKI.logger.info(`(LETSENCRYPT) Received valid challenge request. [ ACCEPTED ]`)
|
||
|
} else {
|
||
|
res.status(406).send('Invalid Challenge Token!')
|
||
|
WIKI.logger.warn(`(LETSENCRYPT) Received invalid challenge request. [ REJECTED ]`)
|
||
|
}
|
||
|
} else {
|
||
|
res.status(418).end()
|
||
|
}
|
||
|
})
|
||
|
|
||
5 years ago
|
/**
|
||
|
* Redirect to HTTPS if HTTP Redirection is enabled
|
||
|
*/
|
||
|
router.all('/*', (req, res, next) => {
|
||
|
if (WIKI.config.server.sslRedir && !req.secure && WIKI.servers.servers.https) {
|
||
|
let query = (!_.isEmpty(req.query)) ? `?${qs.stringify(req.query)}` : ``
|
||
|
return res.redirect(`https://${req.hostname}${req.originalUrl}${query}`)
|
||
|
} else {
|
||
|
next()
|
||
|
}
|
||
|
})
|
||
|
|
||
5 years ago
|
module.exports = router
|