webdav / app.py
sigyllly's picture
Update app.py
d9c2e0e verified
import os
from cheroot import wsgi
from wsgidav.wsgidav_app import WsgiDAVApp
from wsgidav.fs_dav_provider import FilesystemProvider
# Create the files directory and sample.txt
files_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files")
if not os.path.exists(files_dir):
os.makedirs(files_dir)
# Create a sample.txt file
with open(os.path.join(files_dir, "sample.txt"), "w") as f:
f.write("This is a sample file for the WebDAV server.")
print(f"Created 'files' directory with sample.txt at {files_dir}")
# Configuration
config = {
"provider_mapping": {
"/": FilesystemProvider(files_dir)
},
"http_authenticator": {
"domain_controller": None,
},
"simple_dc": {"user_mapping": {"*": True}}, # No authentication
"verbose": 1,
}
# Create the WSGI application
app = WsgiDAVApp(config)
# Create and start the server
server_addr = "0.0.0.0"
server_port = 7860
server = wsgi.Server((server_addr, server_port), app)
print(f"Starting WebDAV server at http://{server_addr}:{server_port}")
try:
server.start()
except KeyboardInterrupt:
print("Stopping server...")
server.stop()