|
4 | 4 |
|
5 | 5 | ## v1.0.2 |
6 | 6 |
|
7 | | -### Relative URLs in v1 Response Bodies |
| 7 | +### Relative URLs in v1 Responses |
8 | 8 |
|
9 | | -URL fields in **v1** API responses are returned as **relative paths** (e.g., `/download/...`) instead of absolute URLs. **v0 (legacy) endpoints continue to return absolute URLs** (`http://{host}/...`) for backward compatibility with existing integrations. |
| 9 | +URL fields in **v1** responses are now **relative paths** (`/...`). **v0 endpoints keep absolute URLs** (`http://{host}/...`) for backward compatibility. |
10 | 10 |
|
11 | | -Affected v1 response fields (REST and WebSocket): |
12 | | -- `src` — download links from `/wsapi/v1/export` |
13 | | -- `videoSrc` — watch URLs in LPR / find / vehicle tracking results |
14 | | -- `image`, `images[]` — event notifications, LPR / VA search image references |
15 | | -- `faceImg`, `orgImg` — face search results |
| 11 | +Affected v1 fields: `src`, `videoSrc`, `image`, `images[]`, `faceImg`, `orgImg`. |
16 | 12 |
|
17 | | -```json |
18 | | -// v1 response |
19 | | -{ |
20 | | - "download": [ |
21 | | - {"src": "/download/task-uuid/CH01.mp4", "fileName": "CH01.mp4"} |
22 | | - ] |
23 | | -} |
24 | | - |
25 | | -// v0 response (legacy — unchanged) |
26 | | -{ |
27 | | - "download": [ |
28 | | - {"src": "http://nvr.example.com/download/task-uuid/CH01.mp4", "fileName": "CH01.mp4"} |
29 | | - ] |
30 | | -} |
31 | | -``` |
32 | | - |
33 | | -The host used for v0 absolute URLs comes from the **Canonical Host** server setting (Web Admin → Server Settings → API) when configured, otherwise falls back to the request's `X-Host` header. |
34 | | - |
35 | | -**Client compatibility (v1)**: |
36 | | -- **Browser clients**: no change required — relative URLs resolve against the page origin automatically. |
37 | | -- **Non-browser clients** (curl, Python `requests`, mobile apps, server-to-server): prepend the API base URL when fetching: |
38 | | - ```javascript |
39 | | - const fullUrl = baseUrl + response.download[0].src; |
40 | | - ``` |
41 | | - |
42 | | -### Why |
43 | | - |
44 | | -Previous absolute URLs embedded the server's `Host:` header verbatim. When the request passed through a reverse proxy that rewrites `Host:`, the wrong hostname was baked into the URL — clients then failed to fetch the resource. Relative paths in v1 eliminate this class of issue and align with future federated multi-NVR group routing. v0 retains absolute URLs to keep existing legacy integrations working without code changes. |
| 13 | +**Why**: absolute URLs embedded the request's `Host:` header verbatim, so a reverse proxy rewriting `Host:` baked the wrong hostname into the URL. Relative paths also align with future multi-NVR group routing. |
45 | 14 |
|
46 | | -### Live Stream URLs Unchanged |
| 15 | +**Client compatibility**: |
| 16 | +- Browsers: no change — relative URLs resolve against the page origin. |
| 17 | +- Non-browser clients (curl, mobile, server-to-server): prepend the API base URL before fetching. |
47 | 18 |
|
48 | | -RTMP / WebSocket-FLV stream URLs in `src` arrays of `/api/v1/vod` (live stream) responses remain **absolute** — these protocols require fully-qualified URLs. |
| 19 | +**Exceptions**: |
| 20 | +- v0 absolute URL host comes from **Canonical Host** (Web Admin → Server Settings → API), falling back to the `X-Host` header. |
| 21 | +- `/api/v1/vod` live stream URLs (RTMP / WebSocket-FLV) remain absolute. |
49 | 22 |
|
50 | 23 | ### Breaking Changes |
51 | 24 |
|
52 | | -None. v0 clients continue to receive absolute URLs as before. New v1 clients receive relative URLs — see "Client compatibility (v1)" above for guidance. |
| 25 | +None. |
53 | 26 |
|
54 | 27 | --- |
55 | 28 |
|
|
0 commit comments