Skip to content

Conversation

@TorstenDittmann
Copy link
Contributor

@TorstenDittmann TorstenDittmann commented Dec 30, 2025

Moving the markdown handling to server hooks, since server endpoints dont use the +error.svelte component.

Summary by CodeRabbit

  • Refactor
    • Reorganized markdown request handling to improve performance and request processing flow. The underlying functionality remains unchanged—markdown content continues to be served seamlessly to end-users.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Walkthrough

This pull request refactors markdown content serving by migrating logic from a dedicated route handler to a new middleware hook. A markdownHandler middleware is added to src/hooks.server.ts that intercepts requests ending with .md, resolves the underlying route by stripping the extension, fetches content via getMarkdownContent, and returns a 200 markdown response or 404 if not found. The existing GET route handler at src/routes/[...slug]/+server.ts that previously performed this same function is removed entirely.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Move markdown handling to server hooks' directly and accurately describes the main change: moving markdown request handling from a route handler to server hooks middleware.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/hooks.server.ts (1)

225-232: Move markdownHandler after wwwRedirecter to ensure consistent subdomain behavior.

The current ordering allows markdown files to be served from the www subdomain before the redirect occurs. This creates inconsistent behavior where www.domain.com/docs/guide.md serves content instead of redirecting to domain.com/docs/guide.md first.

🔎 Proposed fix
 export const handle = sequence(
     Sentry.sentryHandle(),
-    markdownHandler,
     redirecter,
     wwwRedirecter,
+    markdownHandler,
     securityheaders,
     initSession
 );
🧹 Nitpick comments (2)
src/hooks.server.ts (2)

18-20: Consider removing redundant variable assignment.

The intermediate withoutExt variable is assigned to routeId but could be used directly, or routeId could be assigned the result of replace directly.

🔎 Proposed refactor
     // strip trailing ".md" from the pathname to get the underlying route id
-    const withoutExt = pathname.replace(/\.md$/, '');
-    const routeId = withoutExt;
+    const routeId = pathname.replace(/\.md$/, '');

24-24: Consider setting Content-Type header for 404 response.

For consistency, the 404 response could specify a Content-Type header, similar to the success response.

🔎 Proposed refactor
-        return new Response('Not found', { status: 404 });
+        return new Response('Not found', { 
+            status: 404,
+            headers: {
+                'Content-Type': 'text/plain; charset=utf-8'
+            }
+        });
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5e20f60 and 288ae8a.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • src/hooks.server.ts
  • src/routes/[...slug]/+server.ts
💤 Files with no reviewable changes (1)
  • src/routes/[...slug]/+server.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-11-06T19:20:26.393Z
Learnt from: ebenezerdon
Repo: appwrite/website PR: 2573
File: src/lib/utils/blog-mid-cta.ts:49-60
Timestamp: 2025-11-06T19:20:26.393Z
Learning: In the appwrite/website repository's blog system, markdown headings use a custom level mapping where single `#` translates to H2 (section heading) rather than the standard H1. The regex pattern `^(?:\s{0,3})#\s+.+$/gm` is used to match these section headings correctly in `src/lib/utils/blog-mid-cta.ts`.

Applied to files:

  • src/hooks.server.ts
🔇 Additional comments (1)
src/hooks.server.ts (1)

5-5: Verify getMarkdownContent handles path traversal and errors.

Ensure that getMarkdownContent validates the route ID to prevent path traversal attacks (e.g., ../../sensitive-file.md) and handles errors gracefully. The function call at line 22 should also be wrapped in error handling.

@TorstenDittmann TorstenDittmann merged commit c895c94 into main Dec 30, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants