Skip to content

fix: custom domain redirect#261

Open
White-Rose-Dev wants to merge 1 commit intomsgbyte:masterfrom
White-Rose-Dev:master
Open

fix: custom domain redirect#261
White-Rose-Dev wants to merge 1 commit intomsgbyte:masterfrom
White-Rose-Dev:master

Conversation

@White-Rose-Dev
Copy link
Copy Markdown

@White-Rose-Dev White-Rose-Dev commented Apr 8, 2026

Fixed custom-domain routing to only trigger on the root path (/) for HTML GET requests.
This prevents the custom-domain middleware from intercepting other routes (such as status or static page paths), ensuring normal route handling and correct behavior after build.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed custom domain routing to properly handle requests to specific paths, ensuring /p/:slug and /status/:slug routes work correctly on custom domains instead of being incorrectly intercepted.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

The custom-domain interception middleware in Express was refined to only apply to GET requests targeting the root URL path, rather than all GET requests accepting HTML. This prevents other routes like /p/:slug and /status/:slug from being intercepted by custom-domain handling logic.

Changes

Cohort / File(s) Summary
Middleware Path Filtering
src/server/app.ts
Modified custom-domain interception condition to check for root path (req.originalUrl === '/') instead of HTML acceptance header, ensuring only root requests trigger custom-domain logic while other routes bypass it.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A hop, a skip, a route so true,
The root path now gets special vue,
While /p/:slug hops freely by,
Our middleware lets others fly!

🚥 Pre-merge checks | ✅ 3
✅ 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 'fix: custom domain redirect' directly addresses the main change: modifying custom-domain routing to only trigger on the root path, preventing unwanted interception of other routes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/server/app.ts`:
- Line 129: The root-path check in the middleware uses req.originalUrl (in the
conditional that starts with "if (req.method === 'GET' && req.originalUrl ===
'/' && req.accepts('html'))") which includes query strings and therefore misses
requests like "/?ref=..."; change the condition to use req.path (e.g., "req.path
=== '/'") so the check reliably matches only the root path regardless of query
params, leaving the rest of the predicate (req.method === 'GET' and
req.accepts('html')) unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c6f94106-0f27-4408-a7ce-3e1ac0998017

📥 Commits

Reviewing files that changed from the base of the PR and between 200fb22 and 80dac52.

📒 Files selected for processing (1)
  • src/server/app.ts

// Custom domain: only for root path so /p/:slug and /status/:slug are not intercepted
app.use('/*', async (req, res, next) => {
if (req.method === 'GET' && req.accepts('html')) {
if (req.method === 'GET' && req.originalUrl === '/' && req.accepts('html')) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

In Express.js, does req.originalUrlinclude the query string, and isreq.paththe recommended field to match only the URL pathname (e.g.,/)?

💡 Result:

Yes.

  • req.originalUrl includes the query string (e.g. a request to /search?q=something yields "/search?q=something"). [1]
  • req.path is the field that contains only the URL pathname (no query string), so it’s the appropriate choice when you want to match just /, /users, etc. [1]

Note: when called from middleware mounted with app.use('/mount', ...), req.path does not include the mount point. [1]

Sources
[1] Express 5.x API Reference — req.originalUrl and req.path documentation (expressjs.com) (expressjs.com)

Citations:


🏁 Script executed:

# Check if file exists and get context around Line 129
if [ -f src/server/app.ts ]; then
  echo "=== File found. Context around Line 129 ==="
  sed -n '120,140p' src/server/app.ts
else
  echo "File not found"
fi

Repository: msgbyte/tianji

Length of output: 916


Use req.path instead of req.originalUrl for root matching.

Line 129 currently misses root requests that include query params (e.g. /?ref=...) because req.originalUrl includes the query string. This causes custom-domain rendering to be skipped unexpectedly, contradicting the middleware's stated intent to handle "only for root path."

Suggested fix
-  if (req.method === 'GET' && req.originalUrl === '/' && req.accepts('html')) {
+  if (req.method === 'GET' && req.path === '/' && req.accepts('html')) {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (req.method === 'GET' && req.originalUrl === '/' && req.accepts('html')) {
if (req.method === 'GET' && req.path === '/' && req.accepts('html')) {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/server/app.ts` at line 129, The root-path check in the middleware uses
req.originalUrl (in the conditional that starts with "if (req.method === 'GET'
&& req.originalUrl === '/' && req.accepts('html'))") which includes query
strings and therefore misses requests like "/?ref=..."; change the condition to
use req.path (e.g., "req.path === '/'") so the check reliably matches only the
root path regardless of query params, leaving the rest of the predicate
(req.method === 'GET' and req.accepts('html')) unchanged.

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.

1 participant