MCPcopy Create free account
hub / github.com/NativeScript/SimDeck / httpJson

Function httpJson

scripts/integration/webrtc.mjs:343–370  ·  view source on GitHub ↗
(pathname)

Source from the content-addressed store, hash-verified

341}
342
343function httpJson(pathname) {
344 return new Promise((resolve, reject) => {
345 const request = http.get(`${serverUrl}${pathname}`, (response) => {
346 let body = "";
347 response.setEncoding("utf8");
348 response.on("data", (chunk) => {
349 body += chunk;
350 });
351 response.on("end", () => {
352 if (response.statusCode && response.statusCode >= 400) {
353 reject(
354 new Error(`${pathname} returned ${response.statusCode}: ${body}`),
355 );
356 return;
357 }
358 try {
359 resolve(JSON.parse(body));
360 } catch (error) {
361 reject(error);
362 }
363 });
364 });
365 request.on("error", reject);
366 request.setTimeout(1000, () => {
367 request.destroy(new Error("health request timed out"));
368 });
369 });
370}
371
372function pngSize(filePath) {
373 const buffer = fs.readFileSync(filePath);

Callers 1

waitForHealthFunction · 0.70

Calls 4

setTimeoutMethod · 0.80
getMethod · 0.65
destroyMethod · 0.65
parseMethod · 0.45

Tested by

no test coverage detected