( port: number, normalizedProjectDir: string, expectedServerBuildSignature: string | null = null, )
| 113 | * HTTP GET to /__hyperframes_config with a short timeout. |
| 114 | */ |
| 115 | export function detectHyperframesServer( |
| 116 | port: number, |
| 117 | normalizedProjectDir: string, |
| 118 | expectedServerBuildSignature: string | null = null, |
| 119 | ): Promise<DetectionResult> { |
| 120 | return new Promise<DetectionResult>((resolveResult) => { |
| 121 | const req = http.get( |
| 122 | { |
| 123 | hostname: "127.0.0.1", |
| 124 | port, |
| 125 | path: "/__hyperframes_config", |
| 126 | timeout: PROBE_TIMEOUT_MS, |
| 127 | }, |
| 128 | (res) => { |
| 129 | if (res.statusCode !== 200) { |
| 130 | res.resume(); |
| 131 | return resolveResult({ type: "not-hyperframes" }); |
| 132 | } |
| 133 | |
| 134 | let data = ""; |
| 135 | let bytes = 0; |
| 136 | res.on("data", (chunk: Buffer | string) => { |
| 137 | bytes += typeof chunk === "string" ? chunk.length : chunk.byteLength; |
| 138 | if (bytes > PROBE_MAX_BYTES) { |
| 139 | req.destroy(); |
| 140 | return resolveResult({ type: "not-hyperframes" }); |
| 141 | } |
| 142 | data += chunk; |
| 143 | }); |
| 144 | res.on("error", () => { |
| 145 | resolveResult({ type: "not-hyperframes" }); |
| 146 | }); |
| 147 | res.on("end", () => { |
| 148 | try { |
| 149 | const json = JSON.parse(data) as HyperframesConfigResponse; |
| 150 | if (json.isHyperframes !== true) { |
| 151 | return resolveResult({ type: "not-hyperframes" }); |
| 152 | } |
| 153 | |
| 154 | const normalize = (p: string) => resolve(p).replace(/\\/g, "/").toLowerCase(); |
| 155 | |
| 156 | if (normalize(json.projectDir) === normalizedProjectDir) { |
| 157 | if ( |
| 158 | expectedServerBuildSignature !== null && |
| 159 | json.serverBuildSignature !== expectedServerBuildSignature |
| 160 | ) { |
| 161 | return resolveResult({ type: "mismatch", projectName: json.projectName }); |
| 162 | } |
| 163 | return resolveResult({ type: "match" }); |
| 164 | } |
| 165 | |
| 166 | return resolveResult({ type: "mismatch", projectName: json.projectName }); |
| 167 | } catch { |
| 168 | resolveResult({ type: "not-hyperframes" }); |
| 169 | } |
| 170 | }); |
| 171 | }, |
| 172 | ); |
no test coverage detected