MCPcopy
hub / github.com/triggerdotdev/trigger.dev / handleManagementRequest

Function handleManagementRequest

apps/yalt/src/index.ts:89–120  ·  view source on GitHub ↗
(request: Request, env: Env, ctx: ExecutionContext)

Source from the content-addressed store, hash-verified

87}
88
89async function handleManagementRequest(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
90 const authHeader = request.headers.get('authorization');
91 if (!authHeader) {
92 return new Response('Authorization header is required', { status: 401 });
93 }
94
95 const authHeaderParts = authHeader.split(' ');
96 if (authHeaderParts.length !== 2) {
97 return new Response('Authorization header is invalid', { status: 401 });
98 }
99
100 const [authType, authKey] = authHeaderParts;
101
102 if (authType !== 'Bearer') {
103 return new Response('Authorization header is invalid', { status: 401 });
104 }
105
106 if (authKey !== env.SECRET_KEY) {
107 return new Response('Authorization header is invalid', { status: 401 });
108 }
109
110 // Okay now we can actually handle the request
111 // We need to look at the path and see what we are doing
112 // POST /api/tunnels -> create a new tunnel
113 const url = new URL(request.url);
114
115 if (url.pathname === '/api/tunnels' && request.method === 'POST') {
116 return handleCreateTunnel(request, env, ctx);
117 }
118
119 return new Response('Not Found', { status: 404 });
120}
121
122async function handleCreateTunnel(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
123 const tunnelId = env.connections.newUniqueId();

Callers 1

fetchFunction · 0.85

Calls 2

handleCreateTunnelFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…