Skip to content

Conversation

@saitejacodes
Copy link

@saitejacodes saitejacodes commented Nov 9, 2025

Fixes #7156

Problem:
Templates using port 80 (like Paymenter, GitLab, and Pterodactyl) were losing the :80 part in their URLs.
Example: http://example.com:80 became http://example.com.

Reason:
The fqdn() function in InstanceSettings was removing ports, keeping only the scheme and host.

Fix:
Updated fqdn() to:

  • Keep :80 if it’s explicitly defined in the input.
  • Keep all custom ports (e.g. :8080).
  • Skip default HTTPS :443 for clean URLs.

Tested:
✅ Paymenter on port 80 → shows example.com:80
✅ GitLab on port 80 → shows example.com:80
✅ HTTPS and custom ports still work correctly

Summary by CodeRabbit

  • Bug Fixes
    • Fixed domain name configuration to properly handle custom ports and URL schemes, ensuring explicit ports are preserved when specified and standard ports are formatted correctly.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 9, 2025

Walkthrough

The FQDN attribute mutator in InstanceSettings has been reworked to explicitly handle URL schemes and ports. The new logic preserves non-standard ports, explicitly retains port 80 if present in the original input, and omits standard ports (80/443) when not explicitly provided, addressing a bug where port 80 was being stripped from generated URLs.

Changes

Cohort / File(s) Summary
FQDN Attribute Mutator Enhancement
app/Models/InstanceSettings.php
Updated the fqdn attribute accessor/mutator to implement explicit port handling: includes non-standard ports in the URL (e.g., scheme://host:port), preserves port 80 when explicitly present in the input, and omits standard ports (80/443) otherwise.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Attention points:
    • Verify port preservation logic correctly handles edge cases: port 80 in input, port 443, and non-standard ports
    • Confirm the method signature syntax is correct (description mentions missing visibility keyword—ensure public function fqdn(): Attribute is properly restored)
    • Validate that the conditional logic for standard vs. non-standard ports is sound

Poem

🐰 A port in the URL, once lost to the void,
Now hops back with eighty—no more overjoyed!
With schemes and with logic so clear and so bright,
Our rabbit approves: the fix feels just right! 🌟

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: preserving :80 in FQDN when explicitly defined, directly addressing the bug fix objective.
Description check ✅ Passed The description comprehensively covers the problem, root cause, implemented fix, and testing results, though it deviates from the template format by omitting the checklist and structured sections.
Linked Issues check ✅ Passed The code changes directly address issue #7156 by modifying fqdn() to preserve :80 when explicitly defined while maintaining correct handling of other ports and default :443.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the FQDN port handling issue; no unrelated modifications are apparent in the InstanceSettings.php file changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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

@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.

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7bbfa09 and 9d5a50b.

📒 Files selected for processing (1)
  • app/Models/InstanceSettings.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (5)
app/Models/**/*.php

📄 CodeRabbit inference engine (.cursor/rules/application-architecture.mdc)

Keep Eloquent domain models in app/Models; models represent core entities (e.g., Application, Server, Service, Team, Project)

app/Models/**/*.php: Define $fillable for mass assignment protection in Eloquent models
Use $casts for attribute casting (e.g., arrays, enums, datetimes) in Eloquent models
Define relationships using Eloquent relation return types (e.g., BelongsTo, HasMany)

app/Models/**/*.php: Define Eloquent relationships using proper relationship methods with return type hints
Prefer Eloquent ORM and relationships over raw queries or DB:: calls
Prevent N+1 queries by using eager loading when appropriate
When creating new models, also create useful factories and seeders

Files:

  • app/Models/InstanceSettings.php
**/*.php

📄 CodeRabbit inference engine (.cursor/rules/development-workflow.mdc)

**/*.php: Follow PSR-12 coding standards for all PHP code
Format PHP code with Laravel Pint configuration
Run static analysis with PHPStan to ensure type safety in PHP code
Document complex methods with PHPDoc blocks including parameters, return types, and thrown exceptions

**/*.php: Follow PSR-12 PHP coding standards across the codebase
Prefer eager loading and query optimization to prevent N+1 issues in database interactions
Use Laravel best practices for structure, services, and policies

**/*.php: Always use curly braces for control structures in PHP, even for single-line bodies
Use PHP 8 constructor property promotion in __construct() and avoid empty constructors
Always declare explicit return types for functions and methods; add appropriate parameter type hints
Prefer PHPDoc blocks over inline comments; only add inline code comments for very complex logic
When documenting arrays, add useful array shape types in PHPDoc where appropriate
Enum case names should be TitleCase (e.g., FavoritePerson, Monthly)

Files:

  • app/Models/InstanceSettings.php
app/**/*.php

📄 CodeRabbit inference engine (.cursor/rules/development-workflow.mdc)

Use database transactions to group related write operations for consistency in services/controllers/jobs

Files:

  • app/Models/InstanceSettings.php
app/Models/**

📄 CodeRabbit inference engine (.cursor/rules/project-overview.mdc)

Place domain models under app/Models

Files:

  • app/Models/InstanceSettings.php
app/Models/*.php

📄 CodeRabbit inference engine (.cursor/rules/database-patterns.mdc)

app/Models/*.php: When adding new database columns, update the model's $fillable array to allow mass assignment (e.g., for Model::create() and $model->update())
Use UUID primary keys via HasUuids for distributed systems
Enable soft deletes on models that require audit trails using SoftDeletes
Log model activity using the Spatie LogsActivity trait where auditing is required
Define explicit Eloquent relationships (belongsTo/hasMany/etc.) for navigable associations used by queries and eager loading

Files:

  • app/Models/InstanceSettings.php
🧬 Code graph analysis (1)
app/Models/InstanceSettings.php (2)
app/Models/Server.php (1)
  • port (822-829)
docker/coolify-realtime/terminal-server.js (1)
  • host (209-209)

Comment on lines +63 to +75
if ($port && !in_array($port, [80, 443])) {
return "{$scheme}://{$host}:{$port}";
}

return $url->getScheme().'://'.$host;
// explicitly keep :80 if user/template provided it
if ($port === 80 && str_contains($value, ':80')) {
return "{$scheme}://{$host}:{$port}";
}

return "{$scheme}://{$host}";
}
);
}
}
);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Don't drop :443 for HTTP URLs.

As written, http://example.test:443 is rewritten to http://example.test, which breaks any template relying on that non-standard port. We only want to hide :443 for HTTPS defaults; for any other scheme (including HTTP) the explicit port must be kept.

-                // keep :80 or :443 only if explicitly defined
-                if ($port && !in_array($port, [80, 443])) {
-                    return "{$scheme}://{$host}:{$port}";
-                }
-
-                // explicitly keep :80 if user/template provided it
-                if ($port === 80 && str_contains($value, ':80')) {
-                    return "{$scheme}://{$host}:{$port}";
-                }
-
-                return "{$scheme}://{$host}";
+                if ($port === null) {
+                    return "{$scheme}://{$host}";
+                }
+
+                if ($scheme === 'https' && $port === 443) {
+                    return "{$scheme}://{$host}";
+                }
+
+                if ($scheme === 'http' && $port === 80 && ! str_contains($value, ':80')) {
+                    return "{$scheme}://{$host}";
+                }
+
+                return "{$scheme}://{$host}:{$port}";

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/Models/InstanceSettings.php around lines 63 to 75, the current logic
strips :443 for any scheme; change it to only omit default ports per scheme
(omit :80 only for http and omit :443 only for https). Update the initial
port-check so you include the port in the returned URL unless it is the scheme's
default (http+80 or https+443), and preserve explicit user/template-specified
ports (e.g., keep :80 if the original value contained ':80' and keep :443 for
http). Ensure the final return builds the URL without a port only when the port
equals the scheme's default and wasn’t explicitly present in the original
string.

@andrasbacsai
Copy link
Member

This does not fix the issue. It is totally unrelated so I am closing it.

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.

[Bug]: Templates with port 80 getting a url without the port

2 participants