Fix proxyFetch is not defined error in admin_users template

The admin_users.html template is a standalone page that doesn't extend
base.html, so it was missing the proxyFetch function definition needed for
admin user management operations. Added the SCRIPT_ROOT variable and
proxyFetch/buildUrl helper functions directly to the template to support
proxy-aware URL generation.
parent 14da15b4
...@@ -474,6 +474,35 @@ ...@@ -474,6 +474,35 @@
</div> </div>
<script> <script>
// Get the script root from Flask (includes X-Forwarded-Prefix if behind proxy)
const SCRIPT_ROOT = {{ request.script_root | tojson | safe }};
/**
* Build a URL with the correct proxy prefix
* @param {string} path - The path to append (e.g., '/api/dashboard-data')
* @returns {string} The full URL with proxy prefix
*/
function buildUrl(path) {
// Ensure path starts with /
if (!path.startsWith('/')) {
path = '/' + path;
}
// Remove leading slash from script_root if present
const root = SCRIPT_ROOT.startsWith('/') ? SCRIPT_ROOT.slice(1) : SCRIPT_ROOT;
// Combine script root and path
return '/' + root + path;
}
/**
* Make a fetch request with proxy-aware URL
* @param {string} path - The API path
* @param {object} options - Fetch options
* @returns {Promise} Fetch promise
*/
function proxyFetch(path, options = {}) {
return fetch(buildUrl(path), options);
}
// Load registration settings on page load // Load registration settings on page load
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
loadRegistrationSettings(); loadRegistrationSettings();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment