Fix: missing custom port on re-written links

When a link was rewritten and the site is running in a custom
(ie, not protocol standard - http/80, https/443) port, the links
became invalid.

We now include them only when necessary.
This commit is contained in:
mgarciaisaia
2021-05-27 01:02:49 -03:00
parent 61e0c455fc
commit 1f222fe0b1
2 changed files with 4 additions and 2 deletions
+2 -2
View File
@@ -106,7 +106,7 @@ module.exports = function(redis) {
let href = links[i].getAttribute('href')
if(href) {
if(href.startsWith('/wiki/') || href.startsWith('/w/')) {
href = `${protocol}${config.domain}${href}`
href = `${protocol}${config.domain}${custom_port}${href}`
let u = new URL(href)
u.searchParams.append('lang', lang)
href = u.href
@@ -146,7 +146,7 @@ module.exports = function(redis) {
// replace wiki links
const wiki_href_regx = /(href=\"(https:|http:|)\/\/([A-z.]+\.)?(wikipedia.org|wikimedia.org|wikidata.org|mediawiki.org))/gm
data.html = data.html.replace(wiki_href_regx, `href="${protocol}${config.domain}`)
data.html = data.html.replace(wiki_href_regx, `href="${protocol}${config.domain}${custom_port}`)
redis.setex(url, config.setexs.wikipage, data.html, (error) => {
if(error) {
+2
View File
@@ -48,8 +48,10 @@ if(config.https_enabled) {
}
https = require('https').Server(credentials, app)
global.protocol = 'https://'
global.custom_port = config.ssl_port === '443' ? '' : `:${config.ssl_port}`
} else {
global.protocol = 'http://'
global.custom_port = config.nonssl_port === '80' ? '' : `:${config.nonssl_port}`
}
const http = require('http').Server(app)