hedgedoc/lib/config/buildDomainOriginWithProtocol.js
Tilman Vatteroth d7986b1920
Refactor existing code to add the configured domain to connect-src
Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2021-09-16 19:43:20 +02:00

19 lines
585 B
JavaScript

module.exports = {
buildDomainOriginWithProtocol: function (config, baseProtocol) {
const isStandardHTTPsPort = config.protocolUseSSL && config.port === 443
const isStandardHTTPPort = !config.protocolUseSSL && config.port === 80
if (!config.domain) {
return ''
}
let origin = ''
const protocol = baseProtocol + (config.protocolUseSSL ? 's' : '') + '://'
origin = protocol + config.domain
if (config.urlAddPort) {
if (!isStandardHTTPPort || !isStandardHTTPsPort) {
origin += ':' + config.port
}
}
return origin
}
}