core: fix url helper for custom domain#1162
Conversation
WalkthroughThis PR refactors the domain-aware URL prefix calculation in the Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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
packages/hydrooj/src/service/server.tsOops! Something went wrong! :( ESLint: 9.39.4 Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'eslint-plugin-react-hooks' imported from /eslint.config.mjs 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/hydrooj/src/service/server.ts (1)
151-153: 💤 Low valueConsider using nullish coalescing for
rootDomainIdfallback.On lines 151-153, if the host match succeeds but
this.args.domainIdhappens to be an empty string (though unlikely),rootDomainIdwould 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
rootDomainIdis 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
📒 Files selected for processing (1)
packages/hydrooj/src/service/server.ts
Summary by CodeRabbit