MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / injectBridgeIntoIndexHtml

Function injectBridgeIntoIndexHtml

main.js:575–606  ·  view source on GitHub ↗

Inject server-bridge before the first app script (same order as static index.html).

(htmlData, bridgeCode, bridgeReadError)

Source from the content-addressed store, hash-verified

573
574 const puterResponse = await fetch('https://api.puter.com/drivers/call', {
575 method: 'POST',
576 headers: {
577 'Content-Type': 'text/plain;actually=json',
578 'Origin': 'https://puter.com',
579 'Referer': 'https://puter.com/'
580 },
581 body: puterBody
582 });
583
584 let data;
585 const puterRawBody = await puterResponse.text();
586 try {
587 data = puterRawBody ? JSON.parse(puterRawBody) : {};
588 } catch (parseErr) {
589 res.status(502).json({ error: `Invalid response from Puter API (${puterResponse.status})`, details: puterRawBody.slice(0, 500) });
590 return;
591 }
592
593 if (!puterResponse.ok || data.success === false) {
594 const errMsg = data?.error?.message || data?.message || `Puter API error (${puterResponse.status})`;
595 const code = data?.error?.code || data?.code;
596 res.status(puterResponse.status >= 400 ? puterResponse.status : 500).json({ error: errMsg, code, details: data });
597 return;
598 }
599
600 const result = data.result;
601 let chatText;
602 if (typeof result === 'string') {
603 chatText = result;
604 } else if (result?.message?.content) {
605 chatText = result.message.content;
606 } else if (typeof result?.text === 'string') {
607 chatText = result.text;
608 } else if (result != null) {
609 chatText = JSON.stringify(result);

Callers 1

startHttpServerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected