Commit 9d4d61d
committed
feat(integrations): teach externalUrl to handle path-only bases
Address review comment from @Meierschlumpf on PR homarr-labs#5595 about the
integration-middleware externalUrl pass-through.
Reverting middleware to `app?.href ?? null` would have crashed `new URL`
inside `createUrl` for path-only bases (e.g. "/cockpit/"). This commit
makes path-only externalUrl a first-class state instead.
- packages/integrations/src/base/integration.ts: new RenderablePath
class mirrors just enough of the WHATWG URL surface (toString,
pathname, hostname, searchParams) for the existing externalUrl
caller set. The `externalUrl` method branches on `startsWith("/")`
and returns a RenderablePath for path-only bases or a URL for
absolute bases (existing behavior). All 19 caller sites continue to
work unchanged: 17 immediately call `.toString()` and the two
outliers (ntfy reads `.hostname` and `.pathname` for a fallback
title; overseerr returns the value up to a `.toString()` caller in
constructAvatarUrl) keep behaving sensibly for path-only.
- packages/api/src/middlewares/integration.ts: restore
`externalUrl: rest.app?.href ?? null` at both call sites per the
reviewer's suggestion. Path-only hrefs now flow through to
integrations untouched, where the new RenderablePath branch in
createUrl handles them. The same fix automatically resolves the
pre-existing pattern in
packages/request-handler/src/lib/cached-request-integration-job-handler.ts:97
where externalUrl is built the same way.
- packages/integrations/test/base.spec.ts: six new tests covering
absolute and path-only externalUrl, query-param merging in both,
path-embedded query strings combined with extra query-params for
path-only, and the null-externalUrl fallback to integration.url.
Net effect: integrations bound to path-only-href apps render their
hrefs against the user's current origin (e.g. Jellyfin "Watch movie"
links resolve as /signalk-server/... instead of the internal
http://signalk:3000/...). Materially better for the multi-hostname
use case this PR is built for.
resolveServerUrl stays in packages/api/src/router/widgets/app.ts for
the ping endpoint - the server genuinely cannot ping a hostless URL,
so CONFLICT is still the right signal there. The middleware case is
different because the value is rendered, not fetched.1 parent d7bcb27 commit 9d4d61d
3 files changed
Lines changed: 119 additions & 7 deletions
File tree
- packages
- api/src/middlewares
- integrations
- src/base
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
67 | 66 | | |
68 | 67 | | |
69 | 68 | | |
70 | | - | |
| 69 | + | |
71 | 70 | | |
72 | 71 | | |
73 | 72 | | |
| |||
129 | 128 | | |
130 | 129 | | |
131 | 130 | | |
132 | | - | |
| 131 | + | |
133 | 132 | | |
134 | 133 | | |
135 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
85 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
86 | 93 | | |
87 | 94 | | |
88 | 95 | | |
| |||
125 | 132 | | |
126 | 133 | | |
127 | 134 | | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
45 | 88 | | |
46 | 89 | | |
47 | 90 | | |
48 | 91 | | |
49 | 92 | | |
50 | 93 | | |
| 94 | + | |
51 | 95 | | |
52 | 96 | | |
53 | 97 | | |
54 | 98 | | |
55 | 99 | | |
56 | 100 | | |
57 | | - | |
| 101 | + | |
58 | 102 | | |
59 | 103 | | |
60 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
61 | 112 | | |
62 | 113 | | |
63 | 114 | | |
| |||
0 commit comments