Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/server/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ if (env.allowOpenapi) {

// 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.

const customDomain = customDomainManager.findPageDomain(req.hostname);
if (customDomain) {
if (customDomain.type === 'static') {
Expand Down