1.6 KiB
1.6 KiB
Plan: Nextcloud WebDAV Integration (COMPLETED)
Transition from static file hosting to a dynamic SvelteKit (Node.js) application that fetches content directly from Nextcloud.
1. Infrastructure Shift
- Replace
@sveltejs/adapter-staticwith@sveltejs/adapter-node. - Update
svelte.config.jsto use the Node adapter. - Remove
fallback: undefinedand other static-specific configurations.
2. Dependencies
- Install
webdavclient library. - Install
dotenv(handled by SvelteKit's built-in env support).
3. Secure Configuration
- Set up
.envwith:NEXTCLOUD_URLNEXTCLOUD_USERNEXTCLOUD_PASSWORD
- Use
$env/dynamic/privateto access these in server-side code only.
4. Server-Side Data Fetching
- Create
src/lib/server/nextcloud.tsto initialize and export the WebDAV client. - Implement
+page.server.tsfor each content route:- Fetch Markdown content from Nextcloud.
- Return the raw string to the frontend.
- Update
Markdown.svelteto receive and render raw strings instead of fetching from a URL on the client.
5. Asset Proxying
- Create a catch-all server route (e.g.,
src/routes/assets/[...path]/+server.ts). - This route will:
- Authenticate with WebDAV.
- Stream images/files from Nextcloud directly to the browser.
- Update Markdown rendering logic to rewrite image URLs to point to this proxy route.
6. Optimization
- Implement server-side caching to avoid hitting Nextcloud on every single request.
- Implement dynamic route discovery to automatically create pages from Nextcloud folders.