mirror of
https://github.com/Sudo-JHare/FHIRFLARE-IG-Toolkit.git
synced 2025-11-05 13:35:15 +00:00
hotfix
This commit is contained in:
parent
85f980be0a
commit
3f1ac10290
52
app.py
52
app.py
@ -1780,40 +1780,58 @@ def fhir_ui_operations():
|
|||||||
|
|
||||||
# Use a single route to capture everything after /fhir/
|
# Use a single route to capture everything after /fhir/
|
||||||
# The 'path' converter handles slashes. 'subpath' can be empty.
|
# The 'path' converter handles slashes. 'subpath' can be empty.
|
||||||
@app.route('/fhir', defaults={'subpath': ''}, methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|
@app.route('/fhir', defaults={'subpath': ''}, methods=['GET', 'POST', 'PUT', 'DELETE'])
|
||||||
@app.route('/fhir/', defaults={'subpath': ''}, methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|
@app.route('/fhir/', defaults={'subpath': ''}, methods=['GET', 'POST', 'PUT', 'DELETE'])
|
||||||
@app.route('/fhir/<path:subpath>', methods=['GET', 'POST', 'PUT', 'DELETE', 'PATCH'])
|
@app.route('/fhir/<path:subpath>', methods=['GET', 'POST', 'PUT', 'DELETE'])
|
||||||
def proxy_hapi(subpath):
|
def proxy_hapi(subpath):
|
||||||
"""
|
"""
|
||||||
Proxies FHIR requests to either the local HAPI server or a custom
|
Proxies FHIR requests to either the local HAPI server or a custom
|
||||||
target server specified by the 'X-Target-FHIR-Server' header or a query parameter.
|
target server specified by the 'X-Target-FHIR-Server' header.
|
||||||
|
Handles requests to /fhir/ (base, subpath='') and /fhir/<subpath>.
|
||||||
|
The route '/fhir' (no trailing slash) is handled separately for the UI.
|
||||||
"""
|
"""
|
||||||
logger.debug(f"Proxy received request for path: '/fhir/{subpath}'")
|
# Clean subpath just in case prefixes were somehow included
|
||||||
|
clean_subpath = subpath.replace('r4/', '', 1).replace('fhir/', '', 1).strip('/')
|
||||||
|
logger.debug(f"Proxy received request for path: '/fhir/{subpath}', cleaned subpath: '{clean_subpath}'")
|
||||||
|
|
||||||
# Determine the target FHIR server base URL
|
# Determine the target FHIR server base URL
|
||||||
|
# NEW: Check for proxy-target query parameter first
|
||||||
target_server_query = request.args.get('proxy-target')
|
target_server_query = request.args.get('proxy-target')
|
||||||
target_server_header = request.headers.get('X-Target-FHIR-Server')
|
target_server_header = request.headers.get('X-Target-FHIR-Server')
|
||||||
final_base_url = None
|
final_base_url = None
|
||||||
is_custom_target = False
|
is_custom_target = False
|
||||||
|
|
||||||
if target_server_query:
|
if target_server_query:
|
||||||
final_base_url = target_server_query.rstrip('/')
|
try:
|
||||||
is_custom_target = True
|
parsed_url = urlparse(target_server_query)
|
||||||
logger.info(f"Proxy target identified from query parameter: {final_base_url}")
|
if not parsed_url.scheme or not parsed_url.netloc:
|
||||||
|
raise ValueError("Invalid URL format in proxy-target query parameter")
|
||||||
|
final_base_url = target_server_query.rstrip('/')
|
||||||
|
is_custom_target = True
|
||||||
|
logger.info(f"Proxy target identified from query parameter: {final_base_url}")
|
||||||
|
except ValueError as e:
|
||||||
|
logger.warning(f"Invalid URL in proxy-target query parameter: '{target_server_query}'. Falling back. Error: {e}")
|
||||||
|
final_base_url = current_app.config['HAPI_FHIR_URL'].rstrip('/')
|
||||||
|
logger.debug(f"Falling back to default local HAPI due to invalid query: {final_base_url}")
|
||||||
elif target_server_header:
|
elif target_server_header:
|
||||||
final_base_url = target_server_header.rstrip('/')
|
try:
|
||||||
is_custom_target = True
|
parsed_url = urlparse(target_server_header)
|
||||||
logger.info(f"Proxy target identified from header: {final_base_url}")
|
if not parsed_url.scheme or not parsed_url.netloc:
|
||||||
|
raise ValueError("Invalid URL format in X-Target-FHIR-Server header")
|
||||||
|
final_base_url = target_server_header.rstrip('/')
|
||||||
|
is_custom_target = True
|
||||||
|
logger.info(f"Proxy target identified from header: {final_base_url}")
|
||||||
|
except ValueError as e:
|
||||||
|
logger.warning(f"Invalid URL in X-Target-FHIR-Server header: '{target_server_header}'. Falling back. Error: {e}")
|
||||||
|
final_base_url = current_app.config['HAPI_FHIR_URL'].rstrip('/')
|
||||||
|
logger.debug(f"Falling back to default local HAPI due to invalid header: {final_base_url}")
|
||||||
else:
|
else:
|
||||||
final_base_url = current_app.config['HAPI_FHIR_URL'].rstrip('/')
|
final_base_url = current_app.config['HAPI_FHIR_URL'].rstrip('/')
|
||||||
logger.debug(f"No target info found, proxying to default local HAPI: {final_base_url}")
|
logger.debug(f"No target info found, proxying to default local HAPI: {final_base_url}")
|
||||||
|
|
||||||
# Construct the final URL for the target server request. This is the core logical change.
|
# Construct the final URL for the target server request
|
||||||
# The subpath variable now correctly captures the remaining part of the URL after '/fhir/'.
|
# Append the cleaned subpath only if it's not empty
|
||||||
# We construct the final URL by joining the base URL and the subpath.
|
final_url = f"{final_base_url}/{clean_subpath}" if clean_subpath else final_base_url
|
||||||
final_url = f"{final_base_url}/{subpath}" if subpath else final_base_url
|
|
||||||
|
|
||||||
logger.debug(f"Final URL for target server: {final_url}")
|
|
||||||
|
|
||||||
# Prepare headers to forward
|
# Prepare headers to forward
|
||||||
headers_to_forward = {
|
headers_to_forward = {
|
||||||
|
|||||||
@ -382,10 +382,10 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
let fetchedMetadataCache = null;
|
let fetchedMetadataCache = null;
|
||||||
let operationDefinitionCache = {}; // <<< ADD THIS LINE: Cache for fetched OperationDefinitions
|
let operationDefinitionCache = {}; // <<< ADD THIS LINE: Cache for fetched OperationDefinitions
|
||||||
|
|
||||||
// <<< ADD THIS SECTION: Get App Mode >>>
|
const appMode = '{{ app_mode | default("standalone") | lower }}';
|
||||||
const appMode = '{{ app_mode | default("standalone") | lower }}'; // Get mode from Flask
|
const initialFhirServerUrl = '{{ app.config["HAPI_FHIR_URL"] | safe }}';
|
||||||
console.log(`App Mode (Operations): ${appMode}`);
|
console.log(`App Mode (Operations): ${appMode}`);
|
||||||
// <<< END ADD >>>
|
console.log(`Initial FHIR Server URL from config: ${initialFhirServerUrl}`);
|
||||||
|
|
||||||
// --- Helper Functions ---
|
// --- Helper Functions ---
|
||||||
function updateAuthInputsUI() {
|
function updateAuthInputsUI() {
|
||||||
@ -1950,6 +1950,17 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
// --- Initial Page State Setup ---
|
// --- Initial Page State Setup ---
|
||||||
resourceTypesDisplayDiv.style.display = 'none';
|
resourceTypesDisplayDiv.style.display = 'none';
|
||||||
swaggerUiContainer.style.display = 'none';
|
swaggerUiContainer.style.display = 'none';
|
||||||
|
|
||||||
|
// Check if the initial URL from config is the default local Hapi URL
|
||||||
|
const isInitialLocalHapi = initialFhirServerUrl.startsWith('http://localhost:8080');
|
||||||
|
|
||||||
|
// Set the initial state based on the URL from Flask config
|
||||||
|
isUsingLocalHapi = isInitialLocalHapi;
|
||||||
|
if (!isUsingLocalHapi) {
|
||||||
|
// If it's a custom URL, populate the input field with it
|
||||||
|
fhirServerUrlInput.value = initialFhirServerUrl;
|
||||||
|
}
|
||||||
|
|
||||||
updateServerToggleUI(); // Set the initial UI state correctly based on default isUsingLocalHapi = true
|
updateServerToggleUI(); // Set the initial UI state correctly based on default isUsingLocalHapi = true
|
||||||
|
|
||||||
}); // End DOMContentLoaded Listener
|
}); // End DOMContentLoaded Listener
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user