add www-redirect option

This commit is contained in:
teddit 2020-11-25 19:17:35 +01:00
parent e2847c87b2
commit 8b7f699b3b
2 changed files with 17 additions and 4 deletions

13
app.js
View File

@ -37,6 +37,7 @@ global.reddit_access_token = null
global.reddit_refresh_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.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.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 pug = require('pug')
const path = require('path') const path = require('path')
@ -76,6 +77,18 @@ if(https_enabled) {
const http = require('http').Server(app) 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) { if(use_helmet && https_enabled) {
app.use(helmet()) app.use(helmet())
if(use_helmet_hsts) { if(use_helmet_hsts) {

8
dist/css/styles.css vendored
View File

@ -224,12 +224,12 @@ body.dark .comment .body a {
color: #3d99fb; color: #3d99fb;
} }
body.dark header .tabmenu li.active a { body.dark header .tabmenu li.active a {
background: #acacac; background: #acacac;
color: #151515; color: #151515;
} }
body.dark #search form input[type="text"] { body.dark #search form input[type="text"] {
background: #0f0f0f; background: #0f0f0f;
color: white; color: white;
} }
a { a {
color: var(--linkcolor); color: var(--linkcolor);