Files
homm/backend/templates/drf_spectacular/redoc.html
T
apuc 50468e2384 Show a fallback when Swagger UI and ReDoc cannot load
Both pages pull their JavaScript from cdn.jsdelivr.net, which is unreachable
behind an authenticating proxy — the page looked blank with no explanation.

- override drf_spectacular/swagger_ui.html and redoc.html in project
  templates
- if the library is missing or nothing rendered after 4 seconds, show a
  short message with a link to /api/docs/ (the offline reference)
- drop the Google Fonts request from the ReDoc page (also blocked)
- note the behaviour in docs/client-links.md
2026-11-22 23:37:17 +03:00

73 lines
2.7 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
{% block head %}
<title>{{ title|default:"ReDoc" }}</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body { margin: 0; font: 15px/1.55 -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
color: #16212b; background: #fff; }
.api-fallback { display: none; max-width: 640px; margin: 64px auto; padding: 24px;
border: 1px solid #e6e8ec; border-radius: 12px; }
.api-fallback h1 { font-size: 20px; margin: 0 0 10px; }
.api-fallback p { color: #5b6b7a; margin: 0 0 10px; }
.api-fallback a { color: #1c4fd8; }
.api-fallback .btn { display: inline-block; margin-top: 6px; padding: 10px 18px;
background: #14161a; color: #fff; border-radius: 10px;
text-decoration: none; }
</style>
{% endblock head %}
</head>
<body>
{% block body %}
{% if settings %}
<div id="redoc-container"></div>
{% else %}
<redoc spec-url="{{ schema_url }}"></redoc>
{% endif %}
<div class="api-fallback" id="api-fallback">
<h1>ReDoc не загрузился</h1>
<p>Эта страница подгружает библиотеку с CDN, а он недоступен из вашей сети
(закрытый прокси или нет интернета).</p>
<p>Справочник по тем же методам открывается без интернета:</p>
<a class="btn" href="/api/docs/">Открыть справочник API</a>
</div>
<script src="{{ redoc_standalone }}"></script>
<script>
(function () {
function showFallback() {
var node = document.getElementById('api-fallback');
if (node) { node.style.display = 'block'; }
}
{% if settings %}
if (typeof Redoc === 'undefined') {
showFallback();
} else {
try {
Redoc.init("{{ schema_url }}", {{ settings|safe }},
document.getElementById('redoc-container'));
} catch (error) {
showFallback();
}
}
{% else %}
if (typeof Redoc === 'undefined') { showFallback(); }
{% endif %}
setTimeout(function () {
var container = document.getElementById('redoc-container');
if (!container || container.children.length === 0) {
var root = document.querySelector('redoc');
if (!root || !root.children.length) { showFallback(); }
}
}, 4000);
})();
</script>
{% endblock body %}
</body>
</html>