Skip to content

core: fix url helper for custom domain#1162

Open
renbaoshuo wants to merge 1 commit into
hydro-dev:masterfrom
renbaoshuo:fix/custom-domain-url-builder
Open

core: fix url helper for custom domain#1162
renbaoshuo wants to merge 1 commit into
hydro-dev:masterfrom
renbaoshuo:fix/custom-domain-url-builder

Conversation

@renbaoshuo
Copy link
Copy Markdown
Contributor

@renbaoshuo renbaoshuo commented May 14, 2026

Summary by CodeRabbit

  • Refactor
    • Improved internal domain ID resolution logic for URL generation, consolidating host comparison checks and enhancing clarity in domain prefix computation.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

Walkthrough

This PR refactors the domain-aware URL prefix calculation in the this.url() method within packages/hydrooj/src/service/server.ts. The change consolidates host comparison logic by extracting the host from this.domain, computing the target domain ID from explicit caller arguments or current context, deriving the root domain ID by comparing request host against the domain host, and conditionally including the domain prefix only when they differ. The refactoring preserves the original behavior while improving code clarity through better variable naming and logic consolidation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: fixing the url helper for custom domain handling in the core service.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/hydrooj/src/service/server.ts

Oops! Something went wrong! :(

ESLint: 9.39.4

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-react-hooks' imported from /eslint.config.mjs
at Object.getPackageJSONURL (node:internal/modules/package_json_reader:301:9)
at packageResolve (node:internal/modules/esm/resolve:764:81)
at moduleResolve (node:internal/modules/esm/resolve:855:18)
at defaultResolve (node:internal/modules/esm/resolve:988:11)
at #cachedDefaultResolve (node:internal/modules/esm/loader:697:20)
at #resolveAndMaybeBlockOnLoaderThread (node:internal/modules/esm/loader:714:38)
at ModuleLoader.resolveSync (node:internal/modules/esm/loader:746:52)
at #resolve (node:internal/modules/esm/loader:679:17)
at ModuleLoader.getOrCreateModuleJob (node:internal/modules/esm/loader:599:35)
at ModuleJob.syncLink (node:internal/modules/esm/module_job:162:33)


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.

🧹 Nitpick comments (1)
packages/hydrooj/src/service/server.ts (1)

151-153: 💤 Low value

Consider using nullish coalescing for rootDomainId fallback.

On lines 151-153, if the host match succeeds but this.args.domainId happens to be an empty string (though unlikely), rootDomainId would be empty rather than 'system'. Using nullish coalescing (??) instead of the ternary could make the fallback behavior more explicit:

const rootDomainId = (this.request.host && host
    && (host instanceof Array ? host.includes(this.request.host) : this.request.host === host)
    ? this.args.domainId : null) ?? 'system';

This ensures rootDomainId is always either a valid domain ID or 'system', never undefined/null.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/hydrooj/src/service/server.ts` around lines 151 - 153, The current
rootDomainId assignment can yield an empty string from this.args.domainId when
the host match succeeds; change the expression that computes rootDomainId so the
host-match branch returns this.args.domainId or null and then apply nullish
coalescing (?? 'system') to provide the fallback. Locate the assignment to
rootDomainId (uses this.request.host, host, and this.args.domainId) and rewrite
it so the host-match result is combined with ?? 'system' to ensure a non-empty
fallback.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/hydrooj/src/service/server.ts`:
- Around line 151-153: The current rootDomainId assignment can yield an empty
string from this.args.domainId when the host match succeeds; change the
expression that computes rootDomainId so the host-match branch returns
this.args.domainId or null and then apply nullish coalescing (?? 'system') to
provide the fallback. Locate the assignment to rootDomainId (uses
this.request.host, host, and this.args.domainId) and rewrite it so the
host-match result is combined with ?? 'system' to ensure a non-empty fallback.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 11def194-ed74-4bdb-b261-6ab0da707929

📥 Commits

Reviewing files that changed from the base of the PR and between 8dc7a73 and e121b07.

📒 Files selected for processing (1)
  • packages/hydrooj/src/service/server.ts

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