Skip to content

Comments

fix: add ROOT_URL fallback to getURL#38872

Open
aniruddhaadak80 wants to merge 2 commits intoRocketChat:developfrom
aniruddhaadak80:fix/geturl-fallback-rooturl
Open

fix: add ROOT_URL fallback to getURL#38872
aniruddhaadak80 wants to merge 2 commits intoRocketChat:developfrom
aniruddhaadak80:fix/geturl-fallback-rooturl

Conversation

@aniruddhaadak80
Copy link

@aniruddhaadak80 aniruddhaadak80 commented Feb 21, 2026

Proposed changes

This PR adds a fallback to process.env.ROOT_URL in the getURL function when the Site_Url setting is not configured.

Why?

Ensures that the application can still generate valid URLs based on the environment configuration, which is particularly useful during initial setup or in environments where settings haven't been fully populated yet.

Issue(s)

Fixes #38867

Steps to test or reproduce

  1. Ensure Site_Url is not set in the database.
  2. Ensure ROOT_URL is set in the environment.
  3. Call getURL() and observe that it returns a URL based on ROOT_URL instead of an empty string.

Summary by CodeRabbit

  • Documentation

    • Fixed a label in the "Get the Latest News" section to "YouTube" for clarity and consistency.
  • Bug Fixes

    • Added an extra fallback for site URL resolution, improving link construction when primary settings are missing and reducing broken links.

@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: 306b399

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

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@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 3bfeaaf and 306b399.

📒 Files selected for processing (1)
  • apps/meteor/app/utils/server/getURL.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/app/utils/server/getURL.ts

Walkthrough

Updated README label "Youtube" → "YouTube". Changed server URL helper to use settings.get('Site_Url') || process.env.ROOT_URL || '' so ROOT_URL is used when Site_Url is absent before falling back to empty string.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md
Corrected textual label from "Youtube" to "YouTube" in the "Get the Latest News" section.
URL Resolution Fallback
apps/meteor/app/utils/server/getURL.ts
Extended siteUrl fallback to include process.env.ROOT_URL (`settings.get('Site_Url')

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant getURL
    participant Settings
    participant Env

    Caller->>getURL: request absolute site URL
    getURL->>Settings: read 'Site_Url'
    alt Site_Url present
        Settings-->>getURL: return Site_Url
    else Site_Url missing
        getURL->>Env: read ROOT_URL
        alt ROOT_URL present
            Env-->>getURL: return ROOT_URL
        else ROOT_URL missing
            Env-->>getURL: return empty string
        end
    end
    getURL-->>Caller: return resolved site URL (or empty)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 I nudged a label, shiny and true,
I tuck ROOT_URL in when Site_Url flew,
Links hop complete from burrow to blue,
Emails and invites now find their view. 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The README.md change updating 'Youtube' to 'YouTube' is unrelated to the linked issue's objective of fixing the getURL fallback behavior. Remove the README.md label update or move it to a separate PR focused on documentation fixes to keep changes focused on the getURL fallback objective.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding ROOT_URL fallback to the getURL function in a concise, single-sentence format.
Linked Issues check ✅ Passed The PR implements the exact objective from issue #38867: adding fallback to process.env.ROOT_URL when Site_Url is not configured, enabling absolute URL generation.
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 2 files

@aniruddhaadak80 aniruddhaadak80 force-pushed the fix/geturl-fallback-rooturl branch from 985e76a to 3bfeaaf Compare February 21, 2026 10:28
Copy link
Contributor

@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)
apps/meteor/app/utils/server/getURL.ts (1)

16-16: No test coverage for the new fallback path

The PR description outlines a clear, testable scenario (unset Site_Url, set ROOT_URL, call getURL()), but no unit test is added. Consider adding a test to the existing getURL test suite covering this fallback.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/app/utils/server/getURL.ts` at line 16, Add a unit test to the
existing getURL test suite that verifies the fallback path when Site_Url is
unset: mock settings.get to return empty/undefined for 'Site_Url', set
process.env.ROOT_URL to a test URL, call getURL(), and assert the returned value
equals process.env.ROOT_URL; be sure to restore or clear process.env and any
settings mocks after the test to avoid cross-test pollution and reference the
getURL function and settings.get call in the test setup.
📜 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 985e76a.

📒 Files selected for processing (2)
  • README.md
  • 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
🧠 Learnings (2)
📚 Learning: 2026-01-08T15:03:59.621Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 38068
File: apps/meteor/tests/data/apps/app-packages/README.md:14-16
Timestamp: 2026-01-08T15:03:59.621Z
Learning: For the RocketChat/Rocket.Chat repository, do not analyze or report formatting issues (such as hard tabs vs spaces, line breaks, etc.). The project relies on automated linting tools to enforce formatting standards.

Applied to files:

  • README.md
📚 Learning: 2025-11-10T19:06:20.146Z
Learnt from: MartinSchoeler
Repo: RocketChat/Rocket.Chat PR: 37408
File: apps/meteor/client/views/admin/ABAC/useRoomAttributeOptions.tsx:53-69
Timestamp: 2025-11-10T19:06:20.146Z
Learning: In the Rocket.Chat repository, do not provide suggestions or recommendations about code sections marked with TODO comments. The maintainers have already identified these as future work and external reviewers lack the full context about implementation plans and timing.

Applied to files:

  • README.md
⏰ 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 (2)
README.md (1)

118-118: LGTM! Correct capitalization of "YouTube".

apps/meteor/app/utils/server/getURL.ts (1)

16-16: Trailing slash normalization is already applied downstream — no fix needed.

The concern about ROOT_URL trailing slashes causing double-slash URLs is already handled. In _getURL (lib/getURL.ts, line 52), siteUrl is normalized via rtrim(trim(_site_url || ''), '/'), which removes trailing slashes before URL concatenation. The proposed fix to strip ROOT_URL at line 16 is redundant.

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

Nitpick comments:
In `@apps/meteor/app/utils/server/getURL.ts`:
- Line 16: Add a unit test to the existing getURL test suite that verifies the
fallback path when Site_Url is unset: mock settings.get to return
empty/undefined for 'Site_Url', set process.env.ROOT_URL to a test URL, call
getURL(), and assert the returned value equals process.env.ROOT_URL; be sure to
restore or clear process.env and any settings mocks after the test to avoid
cross-test pollution and reference the getURL function and settings.get call in
the test setup.

@aniruddhaadak80 aniruddhaadak80 changed the title fix: fallback to ROOT_URL in getURL fix: add ROOT_URL fallback to getURL Feb 21, 2026
Updates the server-side getURL function to fallback to process.env.ROOT_URL
when the Site_Url setting is not configured.

This ensures valid URL generation during initial setup or in restricted
environments where settings might be missing.

Fixes RocketChat#38867
@aniruddhaadak80 aniruddhaadak80 force-pushed the fix/geturl-fallback-rooturl branch from 3bfeaaf to 306b399 Compare February 21, 2026 10:32
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