fix(js): patch fetch to prepend ROOT_PATH for IIS reverse proxy

All relative /api/... calls automatically get /gomag prefix via
global fetch wrapper in shared.js. ROOT_PATH injected from template.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Claude Agent
2026-03-16 15:19:50 +00:00
parent ced6c0a2d4
commit 49471e9f34
2 changed files with 13 additions and 1 deletions

View File

@@ -1,5 +1,16 @@
// shared.js - Unified utilities for all pages // shared.js - Unified utilities for all pages
// ── Root path patch — prepend ROOT_PATH to all relative fetch calls ───────
(function() {
const _fetch = window.fetch.bind(window);
window.fetch = function(url, ...args) {
if (typeof url === 'string' && url.startsWith('/') && window.ROOT_PATH) {
url = window.ROOT_PATH + url;
}
return _fetch(url, ...args);
};
})();
// ── HTML escaping ───────────────────────────────── // ── HTML escaping ─────────────────────────────────
function esc(s) { function esc(s) {
if (s == null) return ''; if (s == null) return '';

View File

@@ -27,8 +27,9 @@
{% block content %}{% endblock %} {% block content %}{% endblock %}
</main> </main>
<script>window.ROOT_PATH = "{{ rp }}";</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
<script src="{{ rp }}/static/js/shared.js?v=9"></script> <script src="{{ rp }}/static/js/shared.js?v=10"></script>
{% block scripts %}{% endblock %} {% block scripts %}{% endblock %}
</body> </body>
</html> </html>