Routing and the backend proxy
The order in which the frontend server picks the owner of a path, how modules declare backend prefixes, and what the proxy adds and relays.
The frontend server answers each path with one owner, whoever asks and whatever the method. It looks for the owner in the order below.
Who answers a path
The renderer
The renderer answers its icon endpoint (/api/_dms/icons), Vite's URLs, the built assets, and any file it has. A file is a development source, a built asset or a module's public/ file.
In production, a path with a segment that starts with a dot is never a built asset. Vite's build metadata under dist/client/.vite/ stays private, including its compressed copies. A leading /.well-known/ directory is the exception, and its public files are still served.
The module routes
The routes of the modules' dms.server.ts answer every method on their path. A method that the module does not declare on its path answers 405, and a HEAD reaches the GET route. See Server routes.
The backend proxies
The prefixes that the modules declare go to the backend. The renderer proxies no path on its own. The DMS declares /api/** and /dms/** in its dms.server.ts.
The pages
Everything else is a page. On a page path, a method other than GET and HEAD gets a 404. The browser never reaches a backend route outside every declared prefix, such as a page's <page>/pagelayout.
The server prints the result when it starts:
Routing: renderer files, then 21 module routes, then the backend proxies below, then the pages
/file-storage/upload/** -> backend (none), declared by antelopejs__dms-frontend-vue
/file-storage/files/** -> backend (none), declared by antelopejs__dms-frontend-vue
/api/** -> backend (session), declared by antelopejs__dms-frontend-vue
/dms/** -> backend (session), declared by antelopejs__dms-frontend-vue
/ai/** -> backend (session), declared by @antelopejs/dms-assistant-frontend-vue
/i18n/** -> backend (none), declared by @antelopejs/dms-lang-frontend-vue
/media/** -> backend (session), declared by @antelopejs/dms-media-frontend-vue
In development, every answer names its owner in an x-dms-route-owner header. The value is renderer, module:<id>, backend:<pattern>, page or not-found.
Declaring a backend prefix
In dms.server.ts:
server.registerBackendProxy("/api/**"); // auth: "session", the default
server.registerBackendProxy("/media/**", { auth: "none" });
server.registerBackendProxy("/uploads/**", {
auth: "none",
maxBodyBytes: 100 * 1024 * 1024,
});
In the manifest, next to its publicEndpoints:
await AddFrontendModule({
// …
backendProxies: [{ path: "/webhooks/acme/**", auth: "none" }],
});
DMS_BACKEND_PROXIES adds entries of the manifest's shape, as a JSON array:
DMS_BACKEND_PROXIES=[{"path":"/webhooks/acme/**","auth":"none"}]
The options of a declaration:
auth: "session"adds the session's access token to the request asAuthorization: Bearer, on the server. The token never reaches the browser, which holds only the sealed,HttpOnlysession cookie. A request with a method other thanGET,HEADandOPTIONSmust carry the frontend's ownOrigin, or it gets a403. A public endpoint is the exception.auth: "none"never sends the session, so it needs noOrigin. Use it for media, or for a webhook that authenticates its caller itself.maxBodyBytescaps the request body that the proxy streams to the backend, in bytes. A larger declaredContent-Lengthgets a413before the proxy passes on any byte. A chunked body is cut off with a413as soon as it goes over. The server then reads and drops what the client is still sending, for 5 seconds at most, before it closes the connection, so the client receives the413and not a reset connection. There is no cap by default, and the backend applies its own.
A pattern is /x, /x/* (one segment below) or /x/** (the path and everything below). Its first segment is literal, and it must lie outside the renderer's own paths. When two patterns cover a path, the more specific one wins. For one pattern, the declaration of the highest-priority frontend module wins, then the manifest's, with a warning.
dev and prepare read the manifest's backendProxies only when the backend serves them, which it does only for a request that carries the bootstrap credential. When they read the modules from the manifest without that credential, they serve only the prefixes that the modules' dms.server.ts declare. build, and dev in a project, read each module's backendProxies from the project and need no credential for them.
What the proxy sends
Every proxied request relays these headers:
- The client headers that a backend route reads about the browser. They are
User-Agent,X-Content-Language(the interface language),X-Realtime-SessionandX-Realtime-Connection(a tab's realtime session and the browser connection that its tabs share). A module route'sevent.backend()sends the same ones. Accept,Content-TypeandIf-Match. WithIf-Match, a backend route can refuse a write made from a stale copy (412or409).- The client's
OriginandRefereras received, so a public route can check where a beacon comes from. X-Forwarded-For,X-Forwarded-ProtoandX-Forwarded-Host, which the proxy sets itself, so a route can limit each client. BehindDMS_TRUSTED_PROXY_HOPStrusted proxies, the proxy extends the client's ownX-Forwarded-Forwith the socket's address. Otherwise the socket's address replaces it. WhenDMS_CLIENT_IP_HEADERnames a header that the request carries, that header's address replaces both.
The proxy matches the request's normalized path, the one it sends to the backend. A .., %2e%2e or \ therefore cannot reach another route through a declared prefix.
The proxy never relays the client's Cookie or Authorization header. The backend gets the session's token only through auth: "session". The server writes no access log, so a token in a query string, such as the token of a signed file URL, stays out of its output.
Redirects
The proxy never follows a backend redirect. The browser follows it. A 301, 302, 303, 307 or 308 reaches the browser with its status, its Location and the backend's own cookies. A redirect to another site therefore sends the browser there, and the frontend's origin never serves that site's page or its cookies.
The proxy keeps paths as they are. A Location on the backend's origin (DMS_API_BASE_URL) becomes the same path on the frontend's origin when the frontend server sends that path to the backend. That happens when a backend proxy covers the path and no renderer file or module route takes it first (see Who answers a path). For example, http://localhost:5010/api/files/1 reaches the browser as /api/files/1.
A Location on a backend path outside every declared backend proxy, such as http://localhost:5010/exports/report.pdf?token=…, stays an absolute backend URL. The browser follows it to the backend, which must then be reachable from the browser on that origin. The proxy reads a relative Location against the backend URL, and the same rule applies. A Location on another site goes through unchanged. These rules apply to every backend proxy and public endpoint, in development and in production.
Large transfers
The proxy streams the request body to the backend, and the answer back to the client, as they come, whatever their size. It holds neither in memory. A transfer may last an hour. The server allows that long to receive a request, in place of the five minutes that Node.js allows by default, and Node.js's own minute still bounds the headers. Once the backend's answer starts, it has no deadline, only a limit of five minutes between two parts.
The DMS declares the storage's signed URLs, /file-storage/upload/** (PUT, capped at 500 MiB) and /file-storage/files/** (GET, HEAD), with auth: "none", because the token in the URL authenticates them. A backend that is reachable only through the frontend still receives uploads and serves downloads when the storage's baseUrl is the frontend's public URL. Resource keys keep their encoded slashes (%2F), and the storage checks every segment of a key itself.
Response compression
The proxy asks the backend for an uncompressed answer. It compresses eligible text (JSON, text, XML, JavaScript and SVG) of at least 1 KiB, or of unknown length. It picks Brotli or gzip from the qualities in the client's Accept-Encoding. Streaming compression delivers each part as the backend writes it. An eligible answer carries Vary: Accept-Encoding, even when the client receives uncompressed bytes.
The proxy does not compress event streams, ranges, answers marked no-transform, or bodies in an encoding it does not know. If the backend ignores the request for an uncompressed answer, the native fetch decodes the encodings it supports. The proxy then removes the stale encoding and length headers before it relays or compresses that body again. A decoded range from an encoded body returns 502, because its byte offsets no longer describe the body. A HEAD answer and an answer without a body keep their representation headers.
Event streams
The proxy relays a long-lived answer, such as a text/event-stream feed, as the backend writes it, for as long as both sides keep it open. When either side stops, only that response ends:
- A client that leaves closes its backend request. A client that left while its request was being routed opens none.
- A backend stream that breaks, because the backend restarts or the connection drops, ends the client's response. The server keeps serving every other request.
The fetch of Node.js ends a backend answer that sends nothing for 5 minutes (undici's bodyTimeout, 300 s between two chunks). The proxy keeps that limit, because it frees a backend connection whose peer vanished without closing it. An event stream that must stay open through quiet periods sends a comment line (: keepalive) more often than that. The DMS realtime stream sends one every 20 s. A stream that sends none ends after 5 quiet minutes, and the browser's EventSource reconnects on its own after the retry delay that the stream set.