fix: Pick sitemap host from request (#8071)

This commit is contained in:
Faris Ansari 2019-08-02 12:42:00 +05:30 committed by Suraj Shetty
parent afdd485b76
commit c33f7f1e45
2 changed files with 15 additions and 4 deletions

View file

@ -714,9 +714,10 @@ def get_url(uri=None, full_address=False):
return uri
if not host_name:
if hasattr(frappe.local, "request") and frappe.local.request and frappe.local.request.host:
protocol = 'https://' if 'https' == frappe.get_request_header('X-Forwarded-Proto', "") else 'http://'
host_name = protocol + frappe.local.request.host
request_host_name = get_host_name_from_request()
if request_host_name:
host_name = request_host_name
elif frappe.local.site:
protocol = 'http://'
@ -753,6 +754,11 @@ def get_url(uri=None, full_address=False):
return url
def get_host_name_from_request():
if hasattr(frappe.local, "request") and frappe.local.request and frappe.local.request.host:
protocol = 'https://' if 'https' == frappe.get_request_header('X-Forwarded-Proto', "") else 'http://'
return protocol + frappe.local.request.host
def url_contains_port(url):
parts = url.split(':')
return len(parts) > 2

View file

@ -15,7 +15,12 @@ base_template_path = "templates/www/sitemap.xml"
def get_context(context):
"""generate the sitemap XML"""
host = get_request_site_address()
# the site might be accessible from multiple host_names
# for e.g gadgets.erpnext.com and gadgetsinternational.com
# so it should be picked from the request
host = frappe.utils.get_host_name_from_request()
links = []
for route, page in iteritems(get_pages()):
if page.sitemap: