MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / createServer

Function createServer

utils/scripts/dev.js:187–214  ·  view source on GitHub ↗
(port)

Source from the content-addressed store, hash-verified

185// ─── HTTPS + WebSocket server ─────────────────────────────────────────────────
186
187async function createServer(port) {
188 const tls = getDevCert();
189 let server;
190
191 if (tls) {
192 server = https.createServer(tls, handleRequest);
193 } else {
194 log("warn", "No TLS certificate — falling back to HTTP");
195 log("warn", "Install openssl to enable HTTPS for your dev server");
196 const http = require("node:http");
197 server = http.createServer(handleRequest);
198 }
199
200 const wss = new WebSocketServer({ server });
201
202 wss.on("connection", (ws) => {
203 log("info", "App connected via WebSocket");
204 ws.on("error", () => {});
205 });
206
207 return {
208 server,
209 wss,
210 broadcast: (msg) => broadcast(wss, msg),
211 isHttps: !!tls,
212 protocol: tls ? "https" : "http",
213 };
214}
215
216function handleRequest(req, res) {
217 let urlPath = req.url.split("?")[0];

Callers 1

mainFunction · 0.85

Calls 4

getDevCertFunction · 0.85
broadcastFunction · 0.85
logFunction · 0.70
onMethod · 0.45

Tested by

no test coverage detected