diff --git a/index.js b/index.js index 3a28017..d8659a3 100644 --- a/index.js +++ b/index.js @@ -42,13 +42,18 @@ app.set('domain', process.env.DOMAIN || "keyoxide.org") app.set('keyoxide_version', packageData.version) app.set('onion_url', process.env.ONION_URL) +// Middlewares app.use((req, res, next) => { res.setHeader('Permissions-Policy', 'interest-cohort=()') next() }) -app.use('/favicon.svg', express.static('favicon.svg')) -app.use('/robots.txt', express.static('robots.txt')) +if (app.get('onion_url')) { + app.get('/*', (req, res, next) => { + res.header('Onion-Location', app.get('onion_url')) + next() + }) +} app.use(stringReplace({ PLACEHOLDER__PROXY_HOSTNAME: process.env.PROXY_HOSTNAME || 'null' @@ -56,6 +61,10 @@ app.use(stringReplace({ 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('/static', require('./routes/static')) app.use('/util', require('./routes/util')) diff --git a/routes/main.js b/routes/main.js index a756302..d61421b 100644 --- a/routes/main.js +++ b/routes/main.js @@ -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-title')) -if (process.env.ONION_URL) { - router.get('/*', (req, res, next) => { - res.header('Onion-Location', process.env.ONION_URL) - next() - }) -} - router.get('/', (req, res) => { let highlights = [] for (let index = 1; index < 4; index++) {