MCPcopy
hub / github.com/simstudioai/sim / checkInternalApiKey

Function checkInternalApiKey

apps/realtime/src/routes/http.ts:13–31  ·  view source on GitHub ↗
(req: IncomingMessage)

Source from the content-addressed store, hash-verified

11}
12
13function checkInternalApiKey(req: IncomingMessage): { success: boolean; error?: string } {
14 const apiKey = req.headers['x-api-key']
15 const expectedApiKey = env.INTERNAL_API_SECRET
16
17 if (!expectedApiKey) {
18 return { success: false, error: 'Internal API key not configured' }
19 }
20
21 if (!apiKey) {
22 return { success: false, error: 'API key required' }
23 }
24
25 const apiKeyStr = Array.isArray(apiKey) ? apiKey[0] : apiKey
26 if (!apiKeyStr || !safeCompare(apiKeyStr, expectedApiKey)) {
27 return { success: false, error: 'Invalid API key' }
28 }
29
30 return { success: true }
31}
32
33function readRequestBody(req: IncomingMessage): Promise<string> {
34 return new Promise((resolve, reject) => {

Callers 1

createHttpHandlerFunction · 0.70

Calls 1

safeCompareFunction · 0.90

Tested by

no test coverage detected