Open hmafzal opened 9 months ago
CSP is irrelevant for your issue. Are you absolutely sure you have installed the sidecar package in your deployed container? I strongly suspect you have not, because why would it work for you locally?
try this: python manage.py findstatic --verbosity 2 drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
, which works fine for me.
@tfranzel when running that locally or in the deployed container, it's able to find it:
Found 'drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css' here:
/usr/local/lib/python3.10/site-packages/drf_spectacular_sidecar/static/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
/app/staticfiles/drf_spectacular_sidecar/swagger-ui-dist/swagger-ui.css
Looking in the following locations:
/app/merge/static
/usr/local/lib/python3.10/site-packages/rest_framework/static
/usr/local/lib/python3.10/site-packages/adminsortable/static
/usr/local/lib/python3.10/site-packages/versatileimagefield/static
/usr/local/lib/python3.10/site-packages/nested_admin/static
/usr/local/lib/python3.10/site-packages/drf_spectacular_sidecar/static
/usr/local/lib/python3.10/site-packages/colorfield/static
/usr/local/lib/python3.10/site-packages/django_extensions/static
/usr/local/lib/python3.10/site-packages/django/contrib/admin/static
/app/staticfiles
Sorry to say but it makes no sense. I believe you are comparing the wrong container, that is not really exactly what is deployed (flags?, conditional build?). Can't explain it otherwise, since you have it working locally.
@tfranzel I'm fairly certain I'm in the right container. Could there be any other setup steps that are required?
A few other notes, if they're helpful:
collectstatic
in the container, but that doesn't seem to help.STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"
setWe are extending StaticFilesConfig when installing it:
class OurStaticFilesConfig(StaticFilesConfig):
"""Using this app in settings instead of django.contrib.staticfiles in order for these settings to take effect."""
if settings.ENVIRONMENT == Environment.local:
# Don't collect and serve rest_framework files outside of localhost. We don't use the DRF Browsable API
# in prod, and the version of jquery that our version of DRF uses was flagged as a vulnerability.
# It's easiest to just exclude rest_framework static files.
ignore_patterns = ["rest_framework/"]
logger.info(f"Ignoring static files of patterns: {ignore_patterns}")
Describe the bug We are trying to enable Swagger UI through Sidecar. SwaggerUI seems to work fine locally, but when we deploy it no longer works. We see the following stack trace:
To Reproduce We have strict CSP rules so we are following the FAQ here: https://drf-spectacular.readthedocs.io/en/latest/faq.html#my-swagger-ui-and-or-redoc-page-is-blank.
Using:
Expected behavior Swagger UI loads correctly in our deployed site.