Skip to content

Commit

Permalink
[django+js] oprava nefunkcnich API docs na produkci kvuli CSP, odkaz …
Browse files Browse the repository at this point in the history
…na frontend

kvuli inline scriptu
  • Loading branch information
rodlukas committed Apr 15, 2020
1 parent f7179fe commit 2e8fe09
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 23 deletions.
9 changes: 9 additions & 0 deletions admin/static/admin/swagger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const ui = SwaggerUIBundle({
url: "/api/open-api/",
dom_id: "#swagger-ui",
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
layout: "BaseLayout"
})
17 changes: 2 additions & 15 deletions admin/templates/swagger-ui.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{% load static %}
<!DOCTYPE html>
<html lang="cs">
<head>
Expand All @@ -9,20 +10,6 @@
<body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
<script>
const ui = SwaggerUIBundle({
url: "{% url schema_url %}",
dom_id: "#swagger-ui",
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIBundle.SwaggerUIStandalonePreset
],
layout: "BaseLayout",
requestInterceptor: (request) => {
request.headers['X-CSRFToken'] = "{{ csrf_token }}"
return request;
}
})
</script>
<script src="{% static "admin/swagger.js" %}"></script>
</body>
</html>
10 changes: 2 additions & 8 deletions up/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,13 @@
"api/open-api/",
get_schema_view(
title="ÚPadmin API",
description="Dokumentace REST API pro aplikaci ÚPadmin.",
description="Dokumentace *REST API* pro aplikaci **ÚPadmin**. **[Přejít do aplikace](/)**",
version="1.0.0",
),
name="openapi-schema",
),
# Swagger UI dokumentace API
path(
"api/docs/",
TemplateView.as_view(
template_name="swagger-ui.html", extra_context={"schema_url": "openapi-schema"}
),
name="swagger-ui",
),
path("api/docs/", TemplateView.as_view(template_name="swagger-ui.html"), name="swagger-ui"),
# vychozi stranka (serviruje React aplikaci)
re_path(r"^", TemplateView.as_view(template_name="react-autogenerate.html")),
]
Expand Down

0 comments on commit 2e8fe09

Please sign in to comment.