Improve onion middleware

This commit is contained in:
Yarmo Mackenbach 2021-06-21 11:35:59 +02:00
parent 22934fff1d
commit 627890ad4c
No known key found for this signature in database
GPG key ID: 37367F4AF4087AD1
2 changed files with 11 additions and 9 deletions

View file

@ -42,13 +42,18 @@ app.set('domain', process.env.DOMAIN || "keyoxide.org")
app.set('keyoxide_version', packageData.version) app.set('keyoxide_version', packageData.version)
app.set('onion_url', process.env.ONION_URL) app.set('onion_url', process.env.ONION_URL)
// Middlewares
app.use((req, res, next) => { app.use((req, res, next) => {
res.setHeader('Permissions-Policy', 'interest-cohort=()') res.setHeader('Permissions-Policy', 'interest-cohort=()')
next() next()
}) })
app.use('/favicon.svg', express.static('favicon.svg')) if (app.get('onion_url')) {
app.use('/robots.txt', express.static('robots.txt')) app.get('/*', (req, res, next) => {
res.header('Onion-Location', app.get('onion_url'))
next()
})
}
app.use(stringReplace({ app.use(stringReplace({
PLACEHOLDER__PROXY_HOSTNAME: process.env.PROXY_HOSTNAME || 'null' PLACEHOLDER__PROXY_HOSTNAME: process.env.PROXY_HOSTNAME || 'null'
@ -56,6 +61,10 @@ app.use(stringReplace({
contentTypeFilterRegexp: /application\/javascript/, contentTypeFilterRegexp: /application\/javascript/,
})) }))
// Routes
app.use('/favicon.svg', express.static('favicon.svg'))
app.use('/robots.txt', express.static('robots.txt'))
app.use('/', require('./routes/main')) app.use('/', require('./routes/main'))
app.use('/static', require('./routes/static')) app.use('/static', require('./routes/static'))
app.use('/util', require('./routes/util')) app.use('/util', require('./routes/util'))

View file

@ -35,13 +35,6 @@ md.use(require("markdown-it-anchor"), { "level": 2, "permalink": true, "permalin
md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" }) md.use(require("markdown-it-table-of-contents"), { "includeLevel": [2, 3], "listType": "ol" })
md.use(require('markdown-it-title')) md.use(require('markdown-it-title'))
if (process.env.ONION_URL) {
router.get('/*', (req, res, next) => {
res.header('Onion-Location', process.env.ONION_URL)
next()
})
}
router.get('/', (req, res) => { router.get('/', (req, res) => {
let highlights = [] let highlights = []
for (let index = 1; index < 4; index++) { for (let index = 1; index < 4; index++) {