...
This commit is contained in:
@@ -19,6 +19,8 @@ class MarkdownEditorApp:
|
||||
"""Main application that wraps WsgiDAV and adds custom endpoints"""
|
||||
|
||||
def __init__(self, config_path="config.yaml"):
|
||||
self.root_path = Path(__file__).parent.resolve()
|
||||
os.chdir(self.root_path)
|
||||
self.config = self.load_config(config_path)
|
||||
self.collections = self.config.get('collections', {})
|
||||
self.setup_collections()
|
||||
@@ -72,21 +74,26 @@ class MarkdownEditorApp:
|
||||
"""WSGI application entry point"""
|
||||
path = environ.get('PATH_INFO', '')
|
||||
method = environ.get('REQUEST_METHOD', '')
|
||||
|
||||
# Handle collection list endpoint
|
||||
if path == '/fs/' and method == 'GET':
|
||||
return self.handle_collections_list(environ, start_response)
|
||||
|
||||
# Handle static files
|
||||
if path.startswith('/static/'):
|
||||
return self.handle_static(environ, start_response)
|
||||
|
||||
# Handle root - serve index.html
|
||||
|
||||
# Root and index.html
|
||||
if path == '/' or path == '/index.html':
|
||||
return self.handle_index(environ, start_response)
|
||||
|
||||
# All other requests go to WebDAV
|
||||
return self.webdav_app(environ, start_response)
|
||||
# Static files
|
||||
if path.startswith('/static/'):
|
||||
return self.handle_static(environ, start_response)
|
||||
|
||||
# API for collections
|
||||
if path == '/fs/' and method == 'GET':
|
||||
return self.handle_collections_list(environ, start_response)
|
||||
|
||||
# All other /fs/ requests go to WebDAV
|
||||
if path.startswith('/fs/'):
|
||||
return self.webdav_app(environ, start_response)
|
||||
|
||||
# Fallback for anything else (shouldn't happen with correct linking)
|
||||
start_response('404 Not Found', [('Content-Type', 'text/plain')])
|
||||
return [b'Not Found']
|
||||
|
||||
def handle_collections_list(self, environ, start_response):
|
||||
"""Return list of available collections"""
|
||||
@@ -104,9 +111,9 @@ class MarkdownEditorApp:
|
||||
def handle_static(self, environ, start_response):
|
||||
"""Serve static files"""
|
||||
path = environ.get('PATH_INFO', '')[1:] # Remove leading /
|
||||
file_path = Path(path)
|
||||
file_path = self.root_path / path
|
||||
|
||||
if not file_path.exists() or not file_path.is_file():
|
||||
if not file_path.is_file():
|
||||
start_response('404 Not Found', [('Content-Type', 'text/plain')])
|
||||
return [b'File not found']
|
||||
|
||||
@@ -139,9 +146,9 @@ class MarkdownEditorApp:
|
||||
|
||||
def handle_index(self, environ, start_response):
|
||||
"""Serve index.html"""
|
||||
index_path = Path('templates/index.html')
|
||||
index_path = self.root_path / 'templates' / 'index.html'
|
||||
|
||||
if not index_path.exists():
|
||||
if not index_path.is_file():
|
||||
start_response('404 Not Found', [('Content-Type', 'text/plain')])
|
||||
return [b'index.html not found']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user