django / daphne

Django Channels HTTP/WebSocket server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing support for --nostatic and --insecure options in Daphne's runserver command

davidfb opened this issue · comments

The django.contrib.staticfiles app includes a custom runserver command that shadows the default runserver command from Django in order to provide a way of easily serving static files, normally in a dev env.

Daphne's own runserver command is supposed to shadow django.contrib.staticfiles' command as well, if present, and provide all the extra bits and pieces in order to support Django Channels. Serving of static files is still done by leveraging django.contrib.staticfiles' ASGIStaticFilesHandler class, so we could say that, in this particular matter, Daphne is working as a kind of wrapper for django.contrib.staticfiles' functionality. And yet, there are two command arguments (--nostatic and --insecure) that can be passed to django.contrib.staticfiles' runserver that cannot be passed to Daphne's because it doesn't recognize them.

Strangely enough, code at Daphne's command seems to be already prepared to take into account such two configuration options (usages of use_static_handler and insecure_serving options at https://github.com/django/daphne/blob/main/daphne/management/commands/runserver.py#L150 to respectively prevent or force the serving of static files if required to do so), but the command arguments to populate those options are missing.

Is it possible that defining these two command arguments in the runserver command's add_arguments() function was somehow forgotten? Or given the similarities in the naming of such options and in the way they're being used, that exactly matches the code at django.contrib.staticfiles' command (https://github.com/django/django/blob/main/django/contrib/staticfiles/management/commands/runserver.py#L32), could it be that there was a plan to make Daphne's command extend the one from django.contrib.staticfiles, that defines those two arguments, but ended up extending Django core's runserver command instead, thus missing the arguments definition?

We need the ability to avoid serving static files through django.contrib.staticfiles in our dev env because we handle that traffic by other means, and this has been proven problematic when using Daphne.

Thank you.

Ok, yes, this would be a reasonable addition.

Would you like to make a PR?

Thanks.

PR available at #450 waiting for approval.