Skip to content

TXT Proxy API ​

File Information ​

  • Path: server/api/txt/proxy.get.ts
  • Purpose: Server-side proxy for plain-text asset URLs so the in-app text viewer can load cross-origin text files with authentication and avoid CORS issues
  • Method: GET

Overview ​

The client passes a text file URL as the url query parameter. The server validates the URL (must be HTTP or HTTPS), verifies the request has an authenticated user (HTTP-only cookie auth_token), fetches the content from the upstream URL, validates that the response is text (Content-Type: text/*, application/json, application/xml, application/javascript), and streams the response back to the client.

Query Parameters ​

ParameterTypeRequiredDescription
urlstringYesFull URL of the text file to fetch (e.g. asset CDN URL). Must be a valid HTTP or HTTPS URL.

Authentication ​

  • Requires the auth_token HTTP-only cookie. If missing, responds with 401 Unauthorized.

Response ​

  • Success: Streams the text body with appropriate headers (Content-Type, Content-Length, Cache-Control). Default Content-Type if missing: text/plain; charset=utf-8.
  • 400: Missing or invalid url, or unsupported protocol.
  • 401: No auth cookie.
  • 415: Upstream response is not text (Content-Type check).
  • 502 / upstream status: Upstream fetch failed or returned non-2xx.

Usage ​

Used by useTxtViewer (and thus TxtViewer) when the text URL is cross-origin: the viewer requests /api/txt/proxy?url=${encodeURIComponent(textUrl)} with credentials so the server can attach the auth cookie and stream the content.