Skip to content

Comments

fix(utils): fallback to ROOT_URL when Site_Url is not configured in getURL#38868

Open
sahillllllllll-bit wants to merge 1 commit intoRocketChat:developfrom
sahillllllllll-bit:fix/geturl-rooturl-fallback
Open

fix(utils): fallback to ROOT_URL when Site_Url is not configured in getURL#38868
sahillllllllll-bit wants to merge 1 commit intoRocketChat:developfrom
sahillllllllll-bit:fix/geturl-rooturl-fallback

Conversation

@sahillllllllll-bit
Copy link

@sahillllllllll-bit sahillllllllll-bit commented Feb 21, 2026

Proposed changes

getURL currently depends only on the Site_Url setting:

const siteUrl = settings.get<string>('Site_Url') || '';

When Site_Url is not configured (very common during first startup, fresh Docker deployments, or test environments), the server generates relative URLs instead of absolute URLs.

Examples produced:

/api/v1/avatar/user
/assets/logo.svg

Instead of:

http://localhost:3000/api/v1/avatar/user

This function is widely used across the server to generate links for:

  • password reset emails
  • invitation links
  • OAuth redirect URLs
  • notification and integration links

Relative URLs in these contexts break external access because email clients and external authentication providers require absolute URLs.

This PR adds a fallback to process.env.ROOT_URL so the server always produces an absolute URL when Site_Url is not yet configured.

const siteUrl = settings.get<string>('Site_Url') || process.env.ROOT_URL || '';

This keeps the existing behavior unchanged when Site_Url is properly configured.

Issue(s)

Closes #38867
The issue was reproduced locally and the incorrect behavior was also highlighted during automated review.

Steps to test or reproduce

  1. Start Rocket.Chat without configuring Site_Url
  2. Trigger a feature that generates a server link (for example: password reset email or avatar URL)
  3. Before this change → links are relative paths
  4. After this change → links resolve using ROOT_URL (e.g. http://localhost:3000/...)

Further comments

This is a small server-side reliability fix ensuring getURL always returns an absolute URL during initial setup and development environments. It prevents broken links in email flows and authentication callbacks while remaining backward compatible with existing deployments

Summary by CodeRabbit

  • Chores
    • Enhanced URL configuration handling by expanding environment variable fallback support for improved flexibility in server URL resolution.

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 21, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link

changeset-bot bot commented Feb 21, 2026

⚠️ No Changeset found

Latest commit: 94aabef

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 21, 2026

No actionable comments were generated in the recent review. 🎉

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3145c41 and 94aabef.

📒 Files selected for processing (1)
  • apps/meteor/app/utils/server/getURL.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/app/utils/server/getURL.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: cubic · AI code reviewer
🔇 Additional comments (1)
apps/meteor/app/utils/server/getURL.ts (1)

16-16: Remove this review comment — trailing slash normalization is already implemented

The _getURL function (called by getURLWithoutSettings) already strips trailing slashes from siteUrl at line 52 of apps/meteor/app/utils/lib/getURL.ts using rtrim(trim(_site_url || ''), '/'). Leading slashes are stripped from paths at line 57 using ltrim. This normalization applies regardless of whether siteUrl originates from Site_Url or ROOT_URL, so double-slash URLs cannot occur. The proposed fix is unnecessary.

Likely an incorrect or invalid review comment.


Walkthrough

Updated the fallback for siteUrl in the URL helper to consider the ROOT_URL environment variable when Site_Url is not configured. This ensures absolute URLs are generated in scenarios where the setting hasn't been configured yet, such as initial startup or fresh deployments.

Changes

Cohort / File(s) Summary
URL Fallback Configuration
apps/meteor/app/utils/server/getURL.ts
Added fallback to process.env.ROOT_URL environment variable when Site_Url setting is unavailable, ensuring absolute URLs are generated during initial setup and testing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐰 A little hop, a fallback hop,
When Site_Url takes a stop,
ROOT_URL steps right in with cheer,
Absolute URLs, crystal clear!
No more empty strings to fear! 🌐

🚥 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 clearly and specifically describes the main change: adding a fallback to ROOT_URL when Site_Url is not configured in the getURL function.
Linked Issues check ✅ Passed The pull request directly implements the proposed fix from issue #38867, adding ROOT_URL fallback to getURL to generate absolute URLs when Site_Url is unset, addressing all coding requirements.
Out of Scope Changes check ✅ Passed The change is scoped to the single file getURL.ts and implements only the intended fallback behavior; no unrelated modifications are present.
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.


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

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@Rahulyadavv123
Copy link

Rahulyadavv123 commented Feb 21, 2026

@KevLehman i think this is valid bug. wdyt ? and @sahillllllllll-bit can you tell me how to setup rocket.chat locally , in my machine it is showing errors only

@sahillllllllll-bit
Copy link
Author

@KevLehman i think this is valid bug. wdyt ? and @sahillllllllll-bit can you tell me how to setup rocket.chat locally , in my machine it is showing errors only

in your bio written that maintainer and u asking about setup ??

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.

fix(utils): fallback to ROOT_URL when Site_Url is not configured in getURL

2 participants