UNPKG

dt-app

Version:

The Dynatrace App Toolkit is a tool you can use from your command line to create, develop, and deploy apps on your Dynatrace environment.

42 lines (41 loc) 2.1 kB
import type { IncomingMessage } from 'http'; import type { Duplex } from 'stream'; import type { FastifyInstance } from 'fastify'; import type { WebSocketServer } from 'ws'; /** * Minimal structural type for an HTTP(S)/HTTP2 server that emits `upgrade`. * Avoids coupling to a concrete `http.Server` so it also accepts Vite's * `httpServer` (which may be an `Http2SecureServer`). */ type UpgradeableServer = { on(event: 'upgrade', listener: (request: IncomingMessage, socket: Duplex, head: Buffer) => void): unknown; }; /** * Registers an HTTP `upgrade` handler for the Fastify (default) dev server that: * - routes the reserved live-reload path to the internal dev websocket server, and * - proxies every other websocket upgrade to the Dynatrace platform. * * Without this, the internal live-reload websocket server would answer *every* * upgrade, so the app's own websocket connections (e.g. to a backend service) * would be intercepted by the CLI instead of reaching the platform. * * @param server The Fastify instance whose underlying HTTP server emits `upgrade` * @param liveReloadWss The internal live-reload / error-reporting websocket server */ export declare function registerWebSocketUpgradeHandler({ server }: FastifyInstance, liveReloadWss: WebSocketServer): void; /** * Registers an HTTP `upgrade` handler for the Vite (`--hmr`) dev server that * proxies app websocket connections to the Dynatrace platform. * * Vite attaches its own upgrade handler for live reload; it only claims upgrades * carrying a `vite-`-prefixed subprotocol and ignores the rest. This handler * mirrors that contract: it skips Vite's own connections (so HMR keeps working) * and proxies everything else - which Vite would otherwise leave unhandled - to * the platform. * * @param httpServer The underlying HTTP server of the Vite dev server */ export declare function registerViteWebSocketProxy(httpServer: UpgradeableServer | null): void; /** Closes all proxied connections. Used during dev server shutdown. */ export declare function closeWebSocketProxy(): void; export {};