fix(integrations): support UniFi controller default ports - #6210
Conversation
The node-unifi library hardcodes https:// in its base URL and the Unifi controller API only speaks HTTPS. When a user adds the integration with a bare http:// or https:// URL, getPortFromUrl returned 80 or 443, and the library attempted a TLS handshake on the wrong port. The server's plain HTTP response caused 'EPROTO ... wrong version number'. Derive the port from the user's explicit port, or fall back to 8443 (the integration's defaultPort). Closes #6207.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughChangesThe UniFi integration now honors explicit URL ports, retries unspecified-port connections on 443 and 8443 for connection failures, and avoids retrying authentication failures. Tests cover these paths, while UniFi documentation formatting and sitemap route metadata are updated. UniFi controller connection handling
Sequence Diagram(s)sequenceDiagram
participant Integration as UnifiControllerIntegration
participant Controller as UniFi Controller
participant Classifier as Fallback error classifier
Integration->>Controller: Connect on port 443
Controller-->>Integration: Connection failure
Integration->>Classifier: Classify error
Classifier-->>Integration: Retryable
Integration->>Controller: Connect on port 8443
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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/integrations/src/unifi-controller/unifi-controller-integration.ts (1)
64-67: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueOdd comment wording — "ponytail:" looks like a stray artifact.
This prefix doesn't correspond to any known convention and reads as leftover/typo text. Consider cleaning up the comment.
✏️ Suggested cleanup
- // ponytail: node-unifi hardcodes https:// in its base URL and never serves HTTP. + // node-unifi hardcodes https:// in its base URL and never serves HTTP. // Respect the user's explicit port; fall back to 8443 (the integration's defaultPort) // so a bare "http://192.168.1.1" maps to https://192.168.1.1:8443 instead of 80.🤖 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/integrations/src/unifi-controller/unifi-controller-integration.ts` around lines 64 - 67, The comment near the port selection in unifi-controller-integration is carrying a stray “ponytail:” prefix that looks like leftover text. Clean up the inline comment around the port fallback logic in the integration’s URL handling so it reads naturally and only explains the node-unifi HTTPS/defaultPort behavior, without the artifact.
🤖 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/integrations/src/unifi-controller/unifi-controller-integration.ts`:
- Around line 64-67: The comment near the port selection in
unifi-controller-integration is carrying a stray “ponytail:” prefix that looks
like leftover text. Clean up the inline comment around the port fallback logic
in the integration’s URL handling so it reads naturally and only explains the
node-unifi HTTPS/defaultPort behavior, without the artifact.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ad8a51ee-dda2-499d-a4ac-b1cd34910efd
📒 Files selected for processing (2)
packages/integrations/src/unifi-controller/test/unifi-controller-integration.spec.tspackages/integrations/src/unifi-controller/unifi-controller-integration.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@apps/docs/docs/integrations/unifi-controller/index.mdx`:
- Around line 18-19: Correct the typo in the UniFi integration documentation
paragraph by changing “Therfore” to “Therefore”; leave the surrounding content
unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fe419332-082e-4fb5-98b2-303cd06a324c
📒 Files selected for processing (3)
apps/docs/docs/integrations/unifi-controller/index.mdxpackages/integrations/src/unifi-controller/test/unifi-controller-integration.spec.tspackages/integrations/src/unifi-controller/unifi-controller-integration.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- packages/integrations/src/unifi-controller/unifi-controller-integration.ts
| This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller. | ||
| Therfore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers. |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Fix typographical error.
There is a minor typo in the documentation: "Therfore" should be "Therefore".
📝 Proposed fix
This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller.
-Therfore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers.
+Therefore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers.📝 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.
| This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller. | |
| Therfore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers. | |
| This integration is using the [node-unifi](https://www.npmjs.com/package/node-unifi) library under the hood to connect to the Unifi Controller. | |
| Therefore it should support CloudKey Gen1, CloudKey Gen2, UnifiOS-based UDM-Pro controllers as well as self-hosted UniFi controllers. |
🧰 Tools
🪛 LanguageTool
[grammar] ~18-~18: Ensure spelling is correct
Context: ...ood to connect to the Unifi Controller. Therfore it should support CloudKey Gen1, CloudK...
(QB_NEW_EN_ORTHOGRAPHY_ERROR_IDS_1)
🤖 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 `@apps/docs/docs/integrations/unifi-controller/index.mdx` around lines 18 - 19,
Correct the typo in the UniFi integration documentation paragraph by changing
“Therfore” to “Therefore”; leave the surrounding content unchanged.
Source: Linters/SAST tools
Summary
Fixes the misleading TLS error produced when a UniFi integration URL omits its port.
node-unifialways connects over HTTPS. UniFi OS consoles such as UDR and UDM normally use port 443, while self-hosted UniFi Network controllers normally use 8443. Homarr now:The UniFi integration documentation now explains the expected URLs and local-account requirements.
Closes #6207
Test plan
vitest run packages/integrations/src/unifi-controller/test/unifi-controller-integration.spec.ts --coverage.enabled=falsetsc --noEmit -p packages/integrations/tsconfig.jsonoxfmt --checkon the three changed filesoxlinton the changed TypeScript filesSix unit tests cover UniFi OS port 443, fallback to 8443, explicit standard/custom ports, and preventing fallback for authentication errors.
Summary by CodeRabbit