Is there a way for mod_wsgi/Flask and mod_dav to coexist? Is there a way for mod_wsgi/Flask and mod_dav to coexist? apache apache

Is there a way for mod_wsgi/Flask and mod_dav to coexist?


Came back to this a while later, and I've found something that appears to work.

Basically, I'm using mod_rewrite to redirect requests that I don't want mod_wsgi/Flask to handle.

So, if my Flask app is being served under /endpoint, and I want my WebDAV repo to be available under /endpoint/dav, my config is:

RewriteCond %{REQUEST_URI} ^/endpoint/davRewriteCond %{REQUEST_METHOD} ^(PROPFIND|OPTIONS|PROPPATCH)$RewriteRule ^/endpoint/dav /local_path_to_dav_repo/$1 [L]RewriteCond %{REQUEST_URI} ^/endpoint/davRewriteCond %{REQUEST_METHOD} =GETRewriteCond /local_path_to_dav_repo/$1 !-dRewriteRule ^/endpoint/dav(.*) /local_path_to_dav_repo/$1 [L]WSGIScriptAlias /endpoint /my_wsgi_dir/flask.wsgi<Directory /local_path_to_dav_repo>Dav On</Directory>

The first 3 lines grab any DAV-specific method (the read-only ones, for now) and redirect them to the local path of the DAV repo. Because mod_wsgi is only grabbing requests for the /endpoint URI, this request never reaches Flask and goes straight to mod_dav.

The next 4 lines grab any GET requests for specific files and redirect them to the specific location of that file in the local filesystem. Once again, this request doesn't reach Flask. From what I understand, it's faster to have Apache serve the file directly than to have Flask do it.

So the result is that only GET requests for directories in the DAV repo make it to mod_wsgi, so I can build a nice-looking directory index and serve it via Flask.