MCPcopy Create free account
hub / github.com/CopilotKit/aimock / handleHttpRequest

Function handleHttpRequest

src/server.ts:1240–2827  ·  view source on GitHub ↗
(
    req: http.IncomingMessage,
    res: http.ServerResponse,
  )

Source from the content-addressed store, hash-verified

1238 });
1239
1240 async function handleHttpRequest(
1241 req: http.IncomingMessage,
1242 res: http.ServerResponse,
1243 ): Promise<void> {
1244 // OPTIONS preflight
1245 if (req.method === "OPTIONS") {
1246 handleOptions(res);
1247 return;
1248 }
1249
1250 // Record start time for metrics
1251 const startTime = registry ? process.hrtime.bigint() : 0n;
1252
1253 // Parse the URL pathname (strip query string)
1254 const parsedUrl = new URL(req.url ?? "/", `http://${req.headers.host ?? "localhost"}`);
1255 let pathname = parsedUrl.pathname;
1256
1257 // Instrument response completion for metrics. The finish callback reads
1258 // pathname via closure after normalizeCompatPath has rewritten it, so
1259 // metrics record the canonical /v1/... path.
1260 if (registry) {
1261 res.on("finish", () => {
1262 try {
1263 const normalizedPath = normalizePathLabel(pathname);
1264 const method = req.method ?? "UNKNOWN";
1265 const status = String(res.statusCode);
1266 registry.incrementCounter("aimock_requests_total", {
1267 method,
1268 path: normalizedPath,
1269 status,
1270 });
1271 const elapsed = Number(process.hrtime.bigint() - startTime) / 1e9;
1272 registry.observeHistogram(
1273 "aimock_request_duration_seconds",
1274 { method, path: normalizedPath },
1275 elapsed,
1276 );
1277 } catch (err) {
1278 defaults.logger.warn("metrics instrumentation error", err);
1279 }
1280 });
1281 }
1282
1283 // Control API — must be checked before mounts and path rewrites
1284 if (pathname.startsWith(CONTROL_PREFIX)) {
1285 await handleControlAPI(
1286 req,
1287 res,
1288 pathname,
1289 fixtures,
1290 journal,
1291 videoStates,
1292 openRouterVideoJobs,
1293 veoVideoJobs,
1294 grokVideoJobs,
1295 defaults,
1296 );
1297 return;

Callers 1

createServerFunction · 0.85

Calls 15

handleOptionsFunction · 0.85
normalizePathLabelFunction · 0.85
handleControlAPIFunction · 0.85
readBodyFunction · 0.85
handleOllamaFunction · 0.85
writeErrorResponseFunction · 0.85
handleOllamaGenerateFunction · 0.85
handleOllamaEmbeddingsFunction · 0.85
setCorsHeadersFunction · 0.85
flattenHeadersFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…