mirror of
https://github.com/rzuasti/oott.git
synced 2026-07-08 19:21:54 +02:00
Fix API docs link when app is served from the backend
The API docs nav entry uses the origin-relative path "/api/docs", which Uri.parse left scheme- and host-less, so canLaunchUrl/launchUrl could not open it (e.g. in Docker). Resolve external links against the current page so they carry a scheme and host; absolute URLs pass through unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
37075294e3
commit
b0222445fb
@@ -374,8 +374,15 @@ void _onDestinationSelected(_NavDest destination, BuildContext context) {
|
||||
// Opens an external link in a new tab. Origin-relative paths (e.g. the API docs)
|
||||
// resolve against the current host, since the backend serves both the front-end
|
||||
// and the API docs from the same origin.
|
||||
// Resolves an external link against [base] (defaulting to the current page).
|
||||
// Origin-relative paths (e.g. "/api/docs") gain the current scheme and host so
|
||||
// the resulting URI is launchable; absolute URLs are returned unchanged.
|
||||
// Without this, launching a scheme-less URI fails when the app is served from
|
||||
// the backend (e.g. Docker).
|
||||
Uri resolveExternalUri(String url, {Uri? base}) => (base ?? Uri.base).resolve(url);
|
||||
|
||||
Future<void> _openExternal(String url) async {
|
||||
final uri = Uri.parse(url);
|
||||
final uri = resolveExternalUri(url);
|
||||
if (await canLaunchUrl(uri)) {
|
||||
await launchUrl(uri, mode: LaunchMode.externalApplication);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user