add: app property for overriding the scheme used in hrefs
e.g. hrefScheme = https generally renders urls starting with https://
This commit is contained in:
		
							parent
							
								
									9748633b78
								
							
						
					
					
						commit
						dd49a26a57
					
				
					 4 changed files with 19 additions and 11 deletions
				
			
		|  | @ -1467,3 +1467,7 @@ function getLinkCount(item) { | |||
|   } | ||||
|   return (content.match(/https?:\/\//g) || []).length; | ||||
| } | ||||
| 
 | ||||
| function getHrefScheme() { | ||||
|   return getProperty('hrefScheme', 'http') + '://'; | ||||
| } | ||||
|  |  | |||
|  | @ -99,8 +99,8 @@ HopObject.prototype.onRequest = function() { | |||
|   // Checking if we are on the correct host to prevent at least some XSS issues
 | ||||
|   if (req.action !== 'notfound' && req.action !== 'error' && | ||||
|       this.href().contains('://') && | ||||
|       !this.href().toLowerCase().startsWith(req.servletRequest.scheme + | ||||
|       '://' + req.servletRequest.serverName.toLowerCase())) { | ||||
|       !this.href().toLowerCase().startsWith(getHrefScheme() + | ||||
|       req.servletRequest.serverName.toLowerCase())) { | ||||
|     res.redirect(this.href(req.action === 'main' ? String.EMPTY : req.action)); | ||||
|   } | ||||
| 
 | ||||
|  |  | |||
|  | @ -1049,15 +1049,18 @@ Site.prototype.getDiskSpace = function(quota) { | |||
|  * @param {String} href | ||||
|  */ | ||||
| Site.prototype.processHref = function(href) { | ||||
|   var parts, domain, | ||||
|       scheme = (req.servletRequest ? req.servletRequest.scheme : 'http') + '://'; | ||||
|   if (domain = getProperty('domain.' + this.name)) { | ||||
|   var parts; | ||||
|   var scheme = getHrefScheme(); | ||||
|   var domain = getProperty('domain.' + this.name); | ||||
|   if (domain) { | ||||
|     parts = [scheme, domain, href]; | ||||
|   } else if (domain = getProperty('domain.*')) { | ||||
|   } | ||||
|   domain = getProperty('domain.*'); | ||||
|   if (domain) { | ||||
|     parts = [scheme, this.name, '.', domain, href]; | ||||
|   } else { | ||||
|     var mountpoint = app.appsProperties.mountpoint; | ||||
|     (mountpoint === '/') && (mountpoint = ''); // Prevents double slashes
 | ||||
|     if (mountpoint === '/') mountpoint = ''; // Prevents double slashes
 | ||||
|     parts = [scheme, req.data.http_host, mountpoint, href]; | ||||
|   } | ||||
|   return parts.join(''); | ||||
|  | @ -1113,11 +1116,11 @@ Site.prototype.getStaticFile = function(tail) { | |||
|  * @returns {String} | ||||
|  */ | ||||
| Site.prototype.getStaticUrl = function(href) { | ||||
|   href || (href = ''); | ||||
|   var scheme = (req.servletRequest ? req.servletRequest.scheme : 'http') + '://'; | ||||
|   if (!href) href = ''; | ||||
|   var scheme = getHrefScheme(); | ||||
|   var host = getProperty('domain.' + this.name); | ||||
|   host || (host = getProperty('domain.*')); | ||||
|   host || (host = req.data.http_host); | ||||
|   if (!host) host = getProperty('domain.*'); | ||||
|   if (!host) host = req.data.http_host; | ||||
|   return [scheme, host, app.appsProperties.staticMountpoint, '/sites/', this.name, '/', href].join(''); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -47,6 +47,7 @@ cron.nightly.minute = 0 | |||
| baseUri = / | ||||
| hrefFunction = processHref | ||||
| #hrefRootPrototype = Site | ||||
| #hrefScheme = https | ||||
| 
 | ||||
| # List of default and individual domain mappings | ||||
| #domain.* = antville.org | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue