Browser backend
The browser backend is the server-side network boundary for browser deployments of IPTVnator. It gives the browser client one service for provider access, playlist and guide parsing, runtime configuration, health checks, and optional shared browser data. See Client application runtimes for the wider runtime model, Browser client for the user-facing application, and Hosted server and device access for hosted access rules.
Service boundary
The backend turns browser HTTP requests into controlled requests to IPTV providers. It also hosts the browser application in supported deployments, so the client can use one origin for the application, storage, pairing, and provider calls.
Browser services
The service boundary exposes a small set of responsibilities:
| Service | Purpose |
|---|---|
| Runtime configuration | Tells the browser which backend URL to use. |
| Health reporting | Shows whether the backend process is ready to serve requests. |
| Provider registration | Validates a provider URL and returns a target identifier for later calls. |
| Playlist and guide parsing | Downloads M3U or XMLTV data and returns the application data shape. |
| Portal proxying | Relays Xtream and Stalker API requests to providers. |
| Portal connection testing | Reports whether an Xtream connection failed because of HTTP, TLS, or network conditions. |
| Connectivity control | Lets the browser clear a remembered host failure before a deliberate retry. |
| Server storage | Stores playlists and browser state for a shared browser deployment when enabled. |
| Source synchronization | Shares portable source definitions across browser clients without sharing local activity or cached data. |
| Activity synchronization | Shares watched and resume state for supported provider sources across browser clients. |
| TMDB key transfer | Moves a saved TMDB API key between browser clients through a short-lived server session. |
| TV setup pairing | Moves a validated source or settings draft from a phone to the TV that opened the setup session. |
| Hosted browser delivery | Serves the browser application and its API from one controlled local, HTTPS, proxy, or Cloudflare entry point. |
| Hosted device pairing | Enrolls browser devices that use the hosted server and exposes the capabilities allowed by that enrollment. |
The browser client uses the target identifier after registration instead of sending the full provider URL on each proxy call. This keeps provider target handling under backend control and gives the backend one place to apply its network policy. apps/…/web-backend-app.ts• L161-201 and apps/…/pwa.service.ts• L703-733.
References: apps/…/web-backend-app.ts• L147-201 apps/…/web-backend-app.ts• L282-506 apps/…/mount-server-storage.ts• L44-153 apps/…/pwa.service.ts• L703-733
Hosted delivery
Hosted delivery serves the compiled browser application and the backend API from one origin. It supports a local LAN listener, a direct HTTPS listener, a trusted reverse proxy, and a Cloudflare-protected entry point. The listener checks the expected host and browser origin before Express receives a request, and it records trusted ingress in server-side request state rather than trusting client-supplied forwarding headers. apps/…/hosted-listener.ts• L11-79 and apps/…/hosted-ingress.ts• L1-32.
The hosted web app mounts the API below /api, serves the application assets, and returns the application entry page for browser routes. Authorization and discovery paths that belong to Cloudflare stay outside the application fallback, so an edge request that reaches the origin cannot receive the player page. Hosted Xtream responses can also send a small heartbeat while a catalog is being prepared through a tunnel. apps/…/hosted-web-app.ts• L12-45 and apps/…/hosted-xtream-reply.ts• L3-31.
References: apps/…/hosted-listener.ts• L11-79 apps/…/hosted-ingress.ts• L1-32 apps/…/hosted-web-app.ts• L12-45 apps/…/hosted-xtream-reply.ts• L3-31
TV setup pairing
TV setup pairing gives a TV a short-lived session that a phone can use to enter a source or settings draft. The backend keeps the draft in memory and gives the TV and phone separate tokens, so the phone can submit data without gaining the TV's read or completion capability. apps/…/pairing-store.ts• L11-39, apps/…/pairing-store.ts• L40-107
The session moves through a small handshake. It starts as waiting, becomes pending after the phone submits a validated draft, and ends as saved, rejected, or cancelled when the TV acknowledges the result. The phone sees status and safe settings defaults, while only the TV sees the submitted source or settings. The submitted payload is cleared when the session closes. apps/…/pairing-store.ts• L98-142, apps/…/pairing-store.spec.ts• L16-43
The service supports two setup purposes: source entry and settings transfer. Settings defaults are reduced to supported values before they reach the phone, and a replacement TMDB key is returned only to the TV. Sessions expire after a short lifetime and new sessions are bounded by per-address and store-wide limits, which keeps setup links temporary and limits abuse. apps/…/pairing-store.ts• L40-96, apps/…/pairing-store.spec.ts• L45-59, apps/…/pairing-store.spec.ts• L108-175
References: apps/…/pairing-store.ts• L11-174 apps/…/pairing-store.spec.ts• L16-175
Hosted device pairing
Hosted device pairing links a browser device to a hosted server after the device has passed the deployment's access checks. It supports browser claims, device approval, device revocation, and optional Cloudflare enrollment. The server advertises the related capability through instance discovery, while internal worker requests can use the same application without a listening socket. apps/…/device-pairing-router.ts• L18-75, apps/…/instance-router.ts• L25-47, and apps/…/hosted-worker-transport.ts• L11-20.
The pairing routes keep administrative actions on trusted local or worker paths. Browser actions must arrive through the marked hosted ingress and use a short-lived session cookie, while device actions use a device approval token. Cloudflare mode adds an edge access check before an enrolled request can use protected storage routes. apps/…/device-pairing-router.ts• L115-227 and apps/…/mount-server-storage.ts• L71-105.
References: apps/…/device-pairing-router.ts• L18-75 apps/…/device-pairing-router.ts• L115-227 apps/…/device-pairing-router.ts• L260-365 apps/…/mount-server-storage.ts• L49-119 apps/…/hosted-worker-transport.ts• L11-20
Server storage services
Server storage is an optional service for browser deployments that need data to survive browser changes or be shared through one server. It reports the server instance and storage status, stores playlist documents, keeps Xtream user state per playlist, and exposes client app state under the versioned /v1 contract. It also exposes source synchronization when storage is enabled. User-state responses include content tags, so clients can protect changes from overwriting a newer value. apps/…/mount-server-storage.ts• L25-49, apps/…/instance-router.ts• L15-47, apps/…/server-user-state-repository.ts• L23-45, and libs/…/server-storage.contract.ts• L1-54.
The storage API stays separate from provider access but uses the same backend origin and CORS boundary. A deployment can protect storage and provider routes with one bearer token while leaving health, runtime configuration, and instance discovery public. Hosted deployments add instance checks before library edits and can add device or Cloudflare access checks before protected storage work. apps/…/access-guard.ts• L4-51, apps/…/mount-server-storage.ts• L71-150, and apps/…/instance-router.ts• L25-47.
References: apps/…/mount-server-storage.ts• L25-49 apps/…/mount-server-storage.ts• L71-153 apps/…/instance-router.ts• L15-70 apps/…/access-guard.ts• L4-51 apps/…/server-user-state-repository.ts• L23-84 libs/…/server-storage.contract.ts• L1-86
Source synchronization
Source synchronization gives browser clients a shared inventory of portable connection definitions. A source definition describes how to reach an M3U, Xtream, or Stalker source, while local favorites, recent items, playback data, and other runtime state remain outside that portable definition. apps/…/sources-router.ts• L71-80, libs/…/source-definition.util.ts• L22-57, and libs/…/source-definition.util.ts• L90-115.
The inventory supports create, read, edit, and delete operations with revision checks. Creates use If-None-Match: *, edits and deletes require the current source revision, and the collection has its own revision for safe bulk operations. Equivalent sources are returned as the existing canonical entry instead of being duplicated. ETags accept weak forms from a compressing proxy, but update and delete routes still reject * because those actions require a specific revision. apps/…/sources-router.ts• L37-70, apps/…/sources-router.ts• L82-184, and apps/…/etag-match.ts• L1-25.
The source route checks the server instance identity before edits. This prevents a client from applying a change to a different database after a server replacement or restore. The instance endpoint advertises source synchronization as a storage capability, so the browser can discover the service before it uses it. apps/…/sources-router.ts• L26-35 and apps/…/instance-router.ts• L17-26.
References: apps/…/sources-router.ts• L20-184 apps/…/etag-match.ts• L1-25 apps/…/instance-router.ts• L17-26 libs/…/source-definition.util.ts• L22-57 libs/…/source-definition.util.ts• L90-146 apps/…/sources-router.spec.ts• L23-136
Activity synchronization
Activity synchronization gives browser clients a shared view of watched state and playback resume state. It is available for Xtream and Stalker sources through the advertised activity-v1 capability, while local activity remains separate from portable source definitions. apps/…/instance-router.ts• L20-38, apps/…/activity-router.ts• L26-61, and libs/…/activity-sync.contract.ts• L39-90.
The browser verifies the server instance and source context before it reads or changes activity. The server keeps the same activity scope through harmless source edits such as a title or password change, but retires it when the provider identity changes or a source is deleted and recreated. This prevents queued activity from being applied to a different source. apps/…/activity-service.ts• L27-93, apps/…/activity-source-lifecycle.ts• L24-53, and apps/…/activity-router.spec.ts• L204-324.
Activity changes use revisions, playback sessions, ordered checkpoints, and operation IDs. The server applies each accepted operation in one transaction and returns conflicts for stale state or sessions; a repeated operation with the same command returns its saved result instead of changing state twice. libs/…/activity-sync.contract.ts• L52-90, libs/…/activity-sqlite-server.ts• L32-95, and apps/…/activity-router.spec.ts• L71-201.
References: apps/…/activity-router.ts• L10-87 apps/…/activity-service.ts• L17-93 apps/…/activity-source-lifecycle.ts• L10-53 apps/…/activity-router.spec.ts• L40-324 libs/…/activity-sync.contract.ts• L1-117 libs/…/activity-sync.wire.ts• L13-140 libs/…/activity-sqlite-server.ts• L15-142
TMDB key transfer
TMDB key transfer lets a browser client pass a saved TMDB API key to another browser client without placing the key in the transfer code. The server creates a short-lived session with separate sender and receiver tokens. The sender submits the key, the receiver waits for readiness, and one receiver claim consumes the session. apps/…/tmdb-transfer-router.ts• L14-55, apps/…/tmdb-transfer-router.ts• L58-167, and libs/…/source-sync.interface.ts• L44-76.
The transfer is tied to the current server instance and uses the same access and CORS rules as other protected storage calls. It expires after five minutes, supports cancellation, limits transfer traffic, and does not store the key as persistent server data. A receiver claim removes the session before it returns the key, so concurrent claims cannot both succeed. apps/…/tmdb-transfer-router.ts• L14-26, apps/…/tmdb-transfer-router.ts• L44-55, apps/…/tmdb-transfer-router.ts• L121-159, and apps/…/mount-server-storage.ts• L135-150.
References: apps/…/tmdb-transfer-router.ts• L14-167 apps/…/tmdb-transfer-router.spec.ts• L43-135 apps/…/mount-server-storage.ts• L135-150 libs/…/source-sync.interface.ts• L44-76
Provider target lifecycle
Provider target registration is a short-lived process-local mapping from a validated provider URL to a target identifier. A browser request first registers the URL, then uses that identifier for playlist, guide, Xtream, or Stalker work; a backend restart removes the mapping and requires registration again. apps/…/web-backend-app.ts• L173-201, apps/…/web-backend-app.ts• L511-533, and apps/…/pwa.service.ts• L713-733.
Registration checks URL syntax, protocol, credentials, DNS results, and private-network targets. Each outbound request checks the URL again before it connects. Redirects follow the same rule, so a provider cannot use a later hop to escape the network boundary. Private or local targets remain blocked by default, while a trusted deployment can explicitly allow them. apps/…/provider-url-policy.ts• L34-92, apps/…/validated-http-client.ts• L74-97, and apps/…/validated-http-client.ts• L165-187.
References: apps/…/web-backend-app.ts• L173-201 apps/…/web-backend-app.ts• L511-533 apps/…/provider-url-policy.ts• L34-92 apps/…/validated-http-client.ts• L74-97 apps/…/validated-http-client.ts• L165-187
Request services
The backend supplies two kinds of provider work: bulk data preparation for the browser and request forwarding for portal actions. Both use the registered target and return JSON that the browser service can pass to shared application features.
Playlist and guide parsing
Playlist import downloads a remote M3U source and converts it into the playlist structure used by the browser application. Guide import downloads XMLTV data and converts it into channel and programme data. Compressed guide files are also supported, so the browser receives parsed guide data rather than handling compression or XML parsing itself. apps/…/web-backend-app.ts• L232-290 and apps/…/web-backend-app.ts• L603-677.
These download routes are not part of the portal host circuit breaker. They represent a single user-requested or refresh download and can stay active while a healthy source continues to deliver data. They still have bounded inactivity timeouts for a source that stops answering. apps/…/web-backend-app.ts• L232-243, apps/…/web-backend-app.ts• L263-270, and apps/…/host-guard.ts• L1-21.
References: apps/…/web-backend-app.ts• L232-290 apps/…/web-backend-app.ts• L603-677 apps/…/host-guard.ts• L1-21
Xtream and Stalker proxying
Portal proxy routes forward browser requests to the two provider protocols supported by the client. The backend adds the protocol-specific request shape, sends the request from the server, and returns the provider result with the requested action so the browser service can keep its normal portal flow. apps/…/web-backend-app.ts• L292-506.
An explicit Xtream connection test uses the same provider path but returns a small connection result when the request fails. The result lets the browser distinguish an HTTP response from a TLS or network failure and decide whether an HTTP retry is useful. Stalker credentials become request headers rather than ordinary query data. Hosted Cloudflare responses use the same JSON contract while sending periodic whitespace during slow catalog work, which keeps a tunnel from treating an active request as idle. apps/…/web-backend-app.ts• L292-391, apps/…/web-backend-app.ts• L393-506, apps/…/hosted-xtream-reply.ts• L3-31, and libs/…/xtream-connection-test.ts• L3-7.
Redirect handling preserves the first provider response as evidence for connection tests. A redirect to a disallowed address fails before the destination receives a request, while an allowed redirect continues through the same validation and host-failure tracking boundary. apps/…/web-backend-app.redirects.spec.ts• L17-71, apps/…/web-backend-app.redirects.spec.ts• L150-219, and apps/…/web-backend-app.redirects.spec.ts• L316-404.
References: apps/…/web-backend-app.ts• L292-506 apps/…/hosted-xtream-reply.ts• L3-31 apps/…/web-backend-app.redirects.spec.ts• L17-71 apps/…/web-backend-app.redirects.spec.ts• L150-219 apps/…/web-backend-app.redirects.spec.ts• L316-404 libs/…/xtream-connection-test.ts• L3-7
Backend lifecycle
The backend lifecycle has three parts: the Node process opens its optional server storage and creates the HTTP application, the deployment process places that application behind the browser client or hosted listeners, and shutdown closes active work before the process exits. The same backend can run directly for development, beside an Nginx front end in the packaged container, or as the service behind a hosted desktop deployment.
Process startup
The Node entry point applies the shared dual-stack connection setting, reads and validates storage configuration, opens the server database when storage is enabled, and listens on the configured port. An invalid storage setup or an unavailable data directory stops startup before the backend accepts requests. Playwright starts the same entry point as one Node process for end-to-end browser runs. apps/…/main.ts• L39-68, apps/…/project.json• L7-68, apps/…/playwright.config.ts• L94-108, and apps/…/project-config.spec.ts• L4-86.
When the process serves a hosted browser, it requires the shared storage and access configuration, creates the hosted application, and opens the listeners for the selected mode. It can also expose the same backend routes through a private worker transport for the hosting desktop process. Hosted HTTPS changes are serialized with listener shutdown and startup, so the active public origin remains known to the access and pairing services. apps/…/main.ts• L69-163, apps/…/main.ts• L183-245, and apps/…/hosted-https-listener.ts• L10-41.
The application exposes /health as a readiness signal. In a container, the entrypoint waits for this signal before starting Nginx, so the front end does not publish a client that cannot yet reach its backend. apps/…/web-backend-app.ts• L147-150 and docker/docker-entrypoint.sh• L62-84.
References: apps/…/main.ts• L39-163 apps/…/main.ts• L183-263 apps/…/hosted-https-listener.ts• L10-41 apps/…/project.json• L7-68 apps/…/playwright.config.ts• L94-108 apps/…/project-config.spec.ts• L4-86 apps/…/web-backend-app.ts• L147-150 docker/docker-entrypoint.sh• L62-84
Server storage lifecycle
Server storage is enabled only when IPTVNATOR_STORAGE=server. Startup opens the shared IPTVnator SQLite database, adds the server-owned tables for browser data and activity, restores a stable instance identity, and makes the storage routes available; without that setting, the backend remains stateless for browser data. apps/…/storage-config.ts• L1-27, apps/…/server-database.ts• L29-50, apps/…/server-storage.ts• L18-32, and apps/…/main.ts• L47-65.
The storage service gives the browser two views of a playlist: metadata for fast lists and the full document for playback or editing. A server-only metadata copy preserves document fields that are not part of the large M3U payload, so metadata reads do not need to load that payload. Source inventory reads use this metadata view. Full playlist reads normalize older raw uploads into the parsed shape expected by legacy clients, with stable channel identities across repeated reads. apps/…/playlists-router.ts• L18-71, apps/…/server-playlist-repository.ts• L33-141, apps/…/server-playlist-meta.table.ts• L5-57, and apps/…/legacy-source-document.ts• L5-19.
The server stores browser app state separately from server-owned state. Supported Xtream namespaces hold values per playlist, while client keys use a protected prefix so they cannot replace the server instance identity. A stale user-state tag returns the current value with 412 instead of replacing it. Deleting a playlist removes its related user state. apps/…/user-state-router.ts• L12-55, apps/…/server-user-state-repository.ts• L23-84, and libs/…/server-storage.contract.ts• L59-86.
References: apps/…/storage-config.ts• L1-27 apps/…/server-database.ts• L29-50 apps/…/server-storage.ts• L18-32 apps/…/main.ts• L47-65 apps/…/playlists-router.ts• L18-71 apps/…/server-playlist-repository.ts• L33-191 apps/…/server-playlist-meta.table.ts• L5-57 apps/…/legacy-source-document.ts• L5-19 apps/…/user-state-router.ts• L12-73 apps/…/server-user-state-repository.ts• L23-145 libs/…/server-storage.contract.ts• L7-28
Browser delivery
The packaged browser deployment runs the backend and Nginx in one container. Nginx serves the compiled browser files and maps /api/ requests to the Node backend, so the browser uses one public origin for both the application and backend calls. A hosted desktop deployment provides the same one-origin model directly through the hosted web app and its listener checks. docker/nginx.conf#L1-L25, docker/Dockerfile#L31-L53, and apps/…/hosted-web-app.ts• L12-45.
At container startup, the entrypoint writes runtime configuration for the browser and renders the backend port into the Nginx configuration. The same browser build can therefore use a deployment-specific backend URL. The entrypoint monitors both child processes and exits if either one fails. docker/docker-entrypoint.sh• L4-60, docker/docker-entrypoint.sh• L86-109, and apps/…/runtime-config.ts• L3-19.
References: docker/nginx.conf• L1-25 docker/Dockerfile• L31-53 docker/docker-entrypoint.sh• L4-23 docker/docker-entrypoint.sh• L25-60 docker/docker-entrypoint.sh• L86-109 apps/…/hosted-web-app.ts• L12-45 apps/…/hosted-listener.ts• L40-72 apps/…/runtime-config.ts• L3-19
Runtime configuration
The browser reads BACKEND_URL from a runtime script when one is present and otherwise uses the build-time default. A self-hosted deployment can use a relative /api path behind Nginx or the hosted web app, while a development or separate-host deployment can use an absolute backend URL. The backend also controls which browser origins may call it through CLIENT_URL; hosted listeners add an exact host and origin check before this CORS policy. apps/…/runtime-config.ts• L3-19, apps/…/web-backend-app.ts• L113-157, and apps/…/hosted-listener.ts• L40-69.
References: apps/…/runtime-config.ts• L3-19 apps/…/web-backend-app.ts• L113-157 apps/…/hosted-listener.ts• L40-69 apps/…/web-backend-app.ts• L535-557
Process shutdown
The backend treats shutdown as a controlled end to service. On SIGTERM or SIGINT, it stops accepting new connections, closes idle connections, gives active requests a short grace period, then cuts remaining connections before closing server storage and exiting. Hosted shutdown also stops its temporary HTTPS listener and closes all hosted listeners. This prevents a provider stream that never ends from keeping the container or hosted server alive. apps/…/main.ts• L214-263, apps/…/graceful-shutdown.ts• L3-26, and apps/…/hosted-https-listener.ts• L36-41.
References: apps/…/main.ts• L214-263 apps/…/graceful-shutdown.ts• L3-26 apps/…/graceful-shutdown.spec.ts• L12-31 apps/…/hosted-https-listener.ts• L36-41
Provider resilience
The backend protects browser requests from common provider failures without changing the shared client contract. It bounds stalled network work, validates every outbound destination, remembers repeated host-level failures, and returns a small error shape that the browser can classify.
Timeout and host guard
Each provider request has a route-specific inactivity budget. A per-host connectivity guard then stops repeated requests to a host that has failed at the host level, which prevents a dead portal from holding many browser actions open. The outbound client resolves provider host names before connection, validates each redirect, and keeps the approved address separate from provider request authority. apps/…/host-guard.ts• L1-21, apps/…/host-guard.ts• L47-97, apps/…/provider-url-policy.ts• L66-92, and apps/…/validated-http-client.ts• L74-193.
The guard does not treat every error as proof that a host is down. A response from the provider shows that the host is reachable, while a redirect failure is attributed to the failed destination. Stalker discovery can bypass failure counting because most candidate paths are expected to fail. apps/…/host-guard.ts• L117-180 and apps/…/web-backend-app.ts• L402-506.
References: apps/…/host-guard.ts• L1-21 apps/…/host-guard.ts• L47-259 apps/…/provider-url-policy.ts• L66-92 apps/…/validated-http-client.ts• L74-193 apps/…/provider-axios-transport.ts• L22-113 apps/…/web-backend-app.redirects.spec.ts• L221-314
Error responses
Provider errors leave the backend in a predictable JSON shape with a message and status. Network failures also expose a bounded error code when one is available, while server logs record only safe provider details. Portal routes preserve the provider error convention, while explicit Xtream connection tests return connection evidence for the browser's connection flow. apps/…/provider-error.ts• L22-26, apps/…/provider-error.ts• L78-139, apps/…/web-backend-app.ts• L365-386, and libs/…/xtream-connection-test.ts• L3-7.
Storage errors use a separate JSON contract. Invalid documents, missing payloads, oversized bodies, busy databases, and unknown failures map to stable status codes; raw database messages do not reach the browser or server log. apps/…/storage-route-errors.ts• L19-94.
References: apps/…/provider-error.ts• L22-26 apps/…/provider-error.ts• L78-139 apps/…/web-backend-app.ts• L365-386 apps/…/storage-route-errors.ts• L19-94 libs/…/xtream-connection-test.ts• L3-7
Request flow
The request flow separates browser concerns from provider concerns. The browser first selects the backend and registers a provider target, then the backend validates and performs the provider operation before returning application-ready data.
This diagram shows the main path for a browser provider request.
flowchart LR
B[Browser client] --> C[Configured backend URL]
C --> R[Register provider URL]
R --> T[Validated target identifier]
T --> Q[Playlist, guide, Xtream, or Stalker request]
Q --> V[Validate destination and resolve addresses]
V --> G[Origin, redirect, timeout, and host checks]
G --> P[Provider system]
P --> S[Backend response]
S --> B
Registration and later proxy calls are separate steps. The browser service caches the registration promise for a provider URL, while the backend keeps the target in its own process. Before the provider request starts, the outbound client validates the stored URL again and applies the same checks to each redirect. A backend restart therefore affects registration, not the product meaning of the browser request. apps/…/pwa.service.ts• L713-733, apps/…/web-backend-app.ts• L173-201, and apps/…/validated-http-client.ts• L74-193.
Hosted requests add one earlier boundary: the listener accepts only the configured host and origin, then marks the request as trusted ingress for services such as device pairing. Internal worker requests use a private stream instead of a public socket, but they still enter the same Express routes and response contracts. apps/…/hosted-listener.ts• L40-72, apps/…/hosted-ingress.ts• L1-32, and apps/…/hosted-worker-transport.ts• L11-20.
References: apps/…/pwa.service.ts• L713-733 apps/…/web-backend-app.ts• L173-201 apps/…/validated-http-client.ts• L74-193 apps/…/hosted-listener.ts• L40-72 apps/…/hosted-ingress.ts• L1-32 apps/…/hosted-worker-transport.ts• L11-20
Change checklist
When these files or sections are changed, remember to consider these:
- When a backend route or response shape changes, update the matching browser service path and its handling of payload-less provider errors.
- When hosted listener rules change, keep exact host and origin checks, LAN peer checks, TLS and proxy trust, and server-side ingress markers aligned. Do not replace these checks with forwarded client headers.
- When hosted web delivery changes, keep
/apirouting, runtime configuration, static asset behavior, SPA fallback, and Cloudflare authorization paths separate. - When hosted device pairing changes, keep local, browser, device, worker, and Cloudflare roles aligned with their token, cookie, origin, expiry, and approval rules.
- When a hosted API route changes, check both public browser access and private worker access. Preserve the intended access guard and instance status boundary.
- When hosted Xtream replies change, keep the JSON contract unchanged while preserving the tunnel heartbeat and no-transform response behavior.
- When TV setup pairing changes, keep the TV and phone token roles, setup purpose, status transitions, payload visibility, validation, expiry, and attempt limits aligned with both TV and phone flows.
- When source synchronization changes, keep the source capability flag, source-definition validation, fingerprint rules, revision headers, instance identity check, and browser portable-source model aligned.
- When source revisions change, keep weak ETag comparison compatible with compressing proxies while preserving the rule that edits and deletes need an explicit current revision.
- When TMDB key transfer changes, keep the shared request actions, sender and receiver token roles, instance check, expiry behavior, rate limits, single-claim rule, and browser transfer stages aligned.
- When activity synchronization changes, keep the capability flag, instance header, source context, address validation, operation idempotency, and conflict results aligned between the browser and server.
- When source lifecycle rules change, preserve activity across metadata-only edits but invalidate it for provider identity changes and delete/recreate cycles. Keep that decision inside the source write transaction.
- When target registration changes, keep the registration response, target lookup, and browser-side target cache aligned. A mismatch fails all later provider calls.
- When provider URL policy changes, apply the same rule at registration, at each outbound request, and at every redirect hop. Review DNS resolution and private-network handling as one SSRF boundary.
- When the outbound client or provider transport changes, preserve validated-address use, redirect limits, proxy isolation, fixed provider authority, and removal of sensitive headers on cross-origin redirects.
- When
CLIENT_URL,BACKEND_URL, or the reverse-proxy path changes, check browser runtime configuration, CORS origin rules, hosted listener matching, Nginx mapping, and the container health URL together. - When storage routes or the
/v1contract changes, keep shared storage interfaces, source capability discovery, browser data sources, token protection, ETag behavior, and related-state deletion aligned. - When playlist document compatibility changes, keep source inventory projections, full playlist reads, raw M3U reconstruction, and stable channel identity aligned for old uploads.
- When user-state writes change, keep value tags, conditional headers, conflict responses, and playlist deletion cleanup aligned between repository, router, contract, and browser client.
- When storage configuration changes, keep
IPTVNATOR_STORAGE,IPTVNATOR_DATA_DIR, access token, document size limit, startup failure behavior, and instance discovery aligned. - When timeout or host-guard rules change, keep browser route budgets and the corresponding Electron portal behavior aligned where they share the same provider contract.
- When container or hosted process order changes, keep backend readiness before browser publication and keep failure of every child or listener visible to the supervisor.
- When the backend launch command or environment changes, keep the Nx serve target and Playwright single-process launch aligned. Preserve
WEB_BACKEND_PORTand the/healthURL used by end-to-end runs.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A hosted request uses a foreign Host or Origin value | The listener returns 403 before the browser app or API sees the request | Match the configured host and origin at the listener. Do not trust forwarded headers. apps/…/hosted-listener.ts• L40-69 |
| A LAN host is not an active interface or its subnet extends outside the private range | Hosted startup fails instead of exposing the server on an unsafe or missing LAN boundary | Check the selected interface and private subnet before binding. apps/…/hosted-listener.ts• L18-39 |
| Hosted mode starts without server storage or its access token | The hosted child process reports startup failure and does not publish the browser | Require both shared storage and access configuration for hosted mode. apps/…/main.ts• L91-96 |
| A Cloudflare authorization or discovery path reaches the origin | The request receives 404 instead of the player page | Keep /cdn-cgi and /.well-known outside the SPA fallback. apps/…/hosted-web-app.ts• L29-43 |
| A hosted Xtream catalog takes longer than the tunnel idle period | The edge or Android reader can close the request before the catalog is returned | Send bounded heartbeat whitespace and finish with the same JSON body. apps/…/hosted-xtream-reply.ts• L3-31 |
| A browser device pairing request does not arrive through the marked hosted origin | The pairing request is rejected even when its cookie is valid | Require the listener-marked origin, matching host, and matching browser origin. apps/…/device-pairing-router.ts• L115-126 |
| A protected hosted request has not passed Cloudflare access or device enrollment | The server returns 403 before protected storage work | Run the edge check and require an active enrolled device. apps/…/mount-server-storage.ts• L71-92 |
| Phone uses the TV token or the TV uses the phone token | The setup request is rejected and the other role keeps its capability | Keep role-specific tokens separate and compare them in constant time. apps/…/pairing-store.ts• L158-173 |
| A phone submits a second draft or a TV finishes before a draft is pending | The session rejects the action and does not move to an invalid state | Enforce the status sequence and let only the TV finish the session. apps/…/pairing-store.ts• L109-142 |
| A setup link expires or the process restarts | The stored session and draft are unavailable | Open a new setup session. Pairing data is memory-only and time-limited. apps/…/pairing-store.ts• L32-39, apps/…/pairing-store.ts• L149-165 |
| Browser origin is absent from the backend's allowed origin list | Browser HTTP calls are blocked even when the backend and provider are available | Align CLIENT_URL with the deployed browser origin. apps/…/web-backend-app.ts• L132-145 |
| Backend restarts while the browser holds a target identifier | Later provider calls receive Provider target not found | Register the provider URL again when the target is missing. apps/…/web-backend-app.ts• L511-529 |
| Server storage is enabled but its data directory cannot be opened | The backend exits before it serves requests | Give IPTVNATOR_DATA_DIR a writable persistent volume. apps/…/main.ts• L47-65 |
Storage is disabled while the browser expects /v1/playlists | Instance discovery reports no storage and playlist routes are unavailable | Check IPTVNATOR_STORAGE=server before selecting server storage. apps/…/instance-router.ts• L25-47 |
| A source edit or delete omits the current revision | The server rejects the change with 428 instead of risking an overwrite | Read the source ETag and send it in If-Match; use If-None-Match: * only for creation. apps/…/sources-router.ts• L53-70, apps/…/sources-router.ts• L105-119 |
| A stale user-state tag is sent | The newer value is not overwritten; the browser receives 412 with the current entry | Retry from the returned current value and tag. apps/…/user-state-router.ts• L39-54 |
| A TMDB transfer uses the wrong server instance or an expired, cancelled, or already claimed token | The key transfer stops and the browser must close the session or start a new one | Keep the source server instance identity current and use the receiver token for the claim. apps/…/tmdb-transfer-router.ts• L58-69, apps/…/tmdb-transfer-router.ts• L115-155 |
| A legacy uploaded document is returned without its parsed playlist | Whole-document clients cannot use the stored raw M3U in the expected playlist shape | Normalize raw uploads on full reads and keep channel identities stable across repeated reads. apps/…/legacy-source-document.ts• L5-19 |
| Provider URL or a redirect resolves to a private or reserved address | The backend refuses the request before contacting the target | Keep target validation enabled for every request and redirect. apps/…/provider-url-policy.ts• L58-92, apps/…/validated-http-client.ts• L86-187 |
| Provider host accepts a connection and then stops sending data | A browser request can wait until the network stack gives up | Use route timeouts and the per-host connectivity guard. apps/…/host-guard.ts• L47-97 |
| Playwright starts the backend through Nx's detached command wrapper | The backend can outlive the end-to-end run and keep its port in use | Start apps/…/main.ts as one Node process and use the configured health URL. apps/…/project-config.spec.ts• L38-86 |
| Backend is not healthy when Nginx starts | The container publishes a browser client that cannot complete backend calls | Wait for /health before starting Nginx and monitor both child processes. docker/docker-entrypoint.sh• L62-109 |
| Shutdown waits for a provider stream that never ends | Container or hosted termination is delayed until the supervisor kills the process | Close idle connections at once and cut active connections after the grace period. apps/…/graceful-shutdown.ts• L7-26, apps/…/main.ts• L214-263 |
Key files
| File | Why to read it |
|---|---|
| apps/…/project.json | Shows the Node build target and local serve contract for the backend process. |
| apps/…/main.ts | Shows process startup, storage configuration, hosted modes, listeners, worker transport, and shutdown. |
| apps/…/web-backend-app.ts | Defines the public HTTP boundary, provider request services, and storage mount. |
| apps/…/hosted-web-app.ts | Shows how the browser assets, /api routes, hosted pages, and SPA fallback share one origin. |
| apps/…/hosted-listener.ts | Defines local, LAN, HTTPS, and proxy host and origin checks. |
| apps/…/hosted-ingress.ts | Defines trusted ingress and private worker request markers used by hosted access rules. |
| apps/…/hosted-https-listener.ts | Shows how the optional hosted HTTPS listener changes origin without sharing a LAN socket. |
| apps/…/hosted-worker-transport.ts | Shows how hosted desktop work enters the same routes without a public listener. |
| apps/…/hosted-xtream-reply.ts | Defines the hosted tunnel response behavior for slow Xtream catalogs. |
| apps/…/pairing-store.ts | Defines the temporary TV and phone setup session and its capability boundaries. |
| apps/…/pairing-store.spec.ts | Shows the setup session rules for roles, validation, purpose, expiry, and completion. |
| apps/…/mount-server-storage.ts | Shows how discovery, source, playlist, user-state, activity, device pairing, and TMDB transfer routes share access control. |
| apps/…/device-pairing-router.ts | Shows browser claims, device approval, revocation, and hosted access boundaries. |
| apps/…/tmdb-transfer-router.ts | Shows the short-lived, instance-bound TMDB key transfer service. |
| libs/…/source-sync.interface.ts | Defines the transfer actions, token shape, and source server contract shared by browser and backend. |
| apps/…/instance-router.ts | Shows instance identity, storage status, and advertised capabilities. |
| apps/…/sources-router.ts | Shows the shared source inventory, deduplication, instance checks, and revision-protected edits. |
| apps/…/activity-router.ts | Defines the authenticated HTTP boundary for shared activity reads and operations. |
| apps/…/activity-service.ts | Shows how server identity and source identity protect shared activity. |
| apps/…/activity-source-lifecycle.ts | Shows when source changes preserve or retire an activity scope. |
| libs/…/activity-sync.contract.ts | Defines shared activity addresses, playback state, operations, and conflict results. |
| libs/…/activity-sync.wire.ts | Defines the activity capability and the validated browser-to-server request shape. |
| libs/…/activity-sqlite-server.ts | Shows transactional activity updates, receipts, conflicts, and paged reads. |
| apps/…/etag-match.ts | Defines weak ETag matching across browser and compressing proxy boundaries. |
| apps/…/legacy-source-document.ts | Shows how older raw M3U uploads become stable full playlist documents. |
| apps/…/playlist-revisions.ts | Shows per-playlist and collection revisions used by playlist and source synchronization. |
| apps/…/playlists-router.ts | Shows the browser playlist contract, ETags, metadata views, and payload retention. |
| apps/…/server-playlist-repository.ts | Explains the relationship between full playlist documents and payload-free metadata. |
| apps/…/user-state-router.ts | Shows browser user-state writes and conflict responses. |
| apps/…/access-guard.ts | Defines public discovery routes, bearer-token protection, and hosted worker access. |
| apps/…/provider-url-policy.ts | Defines which provider URLs and resolved addresses the backend may contact. |
| apps/…/validated-http-client.ts | Shows the shared outbound boundary for validation and redirects. |
| apps/…/host-guard.ts | Explains request budgets, host failure tracking, and deliberate retry behavior. |
| apps/…/graceful-shutdown.ts | Defines how the server ends active work within a bounded period. |
| libs/…/server-storage.contract.ts | Defines the versioned browser-to-server storage contract. |
| libs/…/source-definition.util.ts | Defines portable source fields, validation, fingerprints, and local-state preservation. |
| apps/…/pwa.service.ts | Shows how the browser registers targets and calls backend services. |
| apps/…/runtime-config.ts | Shows how a browser deployment selects its backend URL. |
| apps/…/playwright.config.ts | Defines the browser test server lifecycle and direct backend launch contract. |
| apps/…/project-config.spec.ts | Protects direct Playwright and TV end-to-end backend launch behavior. |
| docker/docker-entrypoint.sh | Shows container startup, readiness checks, process supervision, and shutdown. |
docker/nginx.conf | Shows the split between static browser delivery and /api/ backend traffic. |
docker/Dockerfile | Shows how the browser client and backend are built and packaged together. |