From 8b7f699b3bcd8bcba8a21553da561cc10af62c89 Mon Sep 17 00:00:00 2001 From: teddit Date: Wed, 25 Nov 2020 19:17:35 +0100 Subject: [PATCH] add www-redirect option --- app.js | 13 +++++++++++++ dist/css/styles.css | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 54495dc..5c28d41 100644 --- a/app.js +++ b/app.js @@ -37,6 +37,7 @@ global.reddit_access_token = null global.reddit_refresh_token = null global.valid_media_domains = ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'] global.reddit_api_error_text = `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.` +global.redirect_www = true const pug = require('pug') const path = require('path') @@ -76,6 +77,18 @@ if(https_enabled) { const http = require('http').Server(app) +if(redirect_www) { + app.use((req, res, next) => { + if(req.headers.host) { + if(req.headers.host.slice(0, 4) === 'www.') { + let newhost = req.headers.host.slice(4) + return res.redirect(301, req.protocol + '://' + newhost + req.originalUrl) + } + } + next() + }) +} + if(use_helmet && https_enabled) { app.use(helmet()) if(use_helmet_hsts) { diff --git a/dist/css/styles.css b/dist/css/styles.css index ab7c56a..34f29f4 100644 --- a/dist/css/styles.css +++ b/dist/css/styles.css @@ -224,12 +224,12 @@ body.dark .comment .body a { color: #3d99fb; } body.dark header .tabmenu li.active a { - background: #acacac; - color: #151515; + background: #acacac; + color: #151515; } body.dark #search form input[type="text"] { - background: #0f0f0f; - color: white; + background: #0f0f0f; + color: white; } a { color: var(--linkcolor);