Fix paths under non-standard virtual directories. Fixes #2563

REL-1_X
Murtuza Zabuawala 2017-07-25 10:15:18 +01:00 committed by Dave Page
parent 617e9dbb3a
commit 178d583bcd
2 changed files with 37 additions and 11 deletions

View File

@ -14,7 +14,7 @@ import os, sys
from collections import defaultdict
from importlib import import_module
from flask import Flask, abort, request, current_app, session
from flask import Flask, abort, request, current_app, session, url_for
from flask_babel import Babel, gettext
from flask_htmlmin import HTMLMIN
from flask_login import user_logged_in
@ -89,13 +89,39 @@ class PgAdmin(Flask):
@property
def exposed_endpoint_url_map(self):
#############################################################
# To handle WSGI paths
# If user has setup application under WSGI alias
# like 'localhost/pgadmin4' then we have to append '/pgadmin4'
# into endpoints
#############################################################
import config
is_wsgi_root_present = False
if config.SERVER_MODE:
pgadmin_root_path = url_for('browser.index')
if pgadmin_root_path != '/browser/':
is_wsgi_root_present = True
wsgi_root_path = pgadmin_root_path.replace(
'/browser/', ''
)
def get_full_url_path(url):
"""
Generate endpoint URL at per WSGI alias
"""
if is_wsgi_root_present and url:
return wsgi_root_path + url
else:
return url
# Fetch all endpoints and their respective url
for rule in current_app.url_map.iter_rules('static'):
yield rule.endpoint, rule.rule
yield rule.endpoint, get_full_url_path(rule.rule)
for module in self.submodules:
for endpoint in module.exposed_endpoints:
for rule in current_app.url_map.iter_rules(endpoint):
yield rule.endpoint, rule.rule
yield rule.endpoint, get_full_url_path(rule.rule)
@property
def javascripts(self):

View File

@ -41,14 +41,14 @@
slickgrid: "{{ url_for('static', filename='js/generated/slickgrid') }}",
codemirror: "{{ url_for('static', filename='js/generated/codemirror') }}",
datagrid: "{{ url_for('static', filename='js/generated/datagrid') }}",
sqleditor: "{{ url_for('static', filename='js/generated/sqleditor') }}"
,'browser_node': "{{ url_for('static', filename='js/generated/browser_node') }}"
,'pgadmin.browser.utils': "/browser/js/utils"
,'pgadmin.browser.endpoints': "/browser/js/endpoints"
,'pgadmin.browser.messages': "/browser/js/messages"
,'pgadmin.server.supported_servers': "/browser/server/supported_servers"
,'pgadmin.user_management.current_user': "/user_management/current_user"
,'translations': "/tools/translations"
sqleditor: "{{ url_for('static', filename='js/generated/sqleditor') }}",
'browser_node': "{{ url_for('static', filename='js/generated/browser_node') }}",
'pgadmin.browser.utils': "{{ url_for('browser.index') }}" + "js/utils",
'pgadmin.browser.endpoints': "{{ url_for('browser.index') }}" + "js/endpoints",
'pgadmin.browser.messages': "{{ url_for('browser.index') }}" + "js/messages",
'pgadmin.server.supported_servers': "{{ url_for('browser.index') }}" + "server/supported_servers",
'pgadmin.user_management.current_user': "{{ url_for('user_management.index') }}" + "current_user",
'translations': "{{ url_for('tools.index') }}" + "translations"
}
});