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

Function fetch

apps/proxy/src/index.ts:19–46  ·  view source on GitHub ↗
(request: Request, env: Env, ctx: ExecutionContext)

Source from the content-addressed store, hash-verified

17
18export default {
19 async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
20 if (!env.REWRITE_HOSTNAME) throw new Error("Missing REWRITE_HOSTNAME");
21 console.log("url", request.url);
22
23 if (!queueingIsEnabled(env)) {
24 console.log("Missing AWS credentials. Passing through to the origin.");
25 return redirectToOrigin(request, env);
26 }
27
28 const url = new URL(request.url);
29 switch (url.pathname) {
30 case "/api/v1/events": {
31 if (request.method === "POST") {
32 return applyRateLimit(request, env, () => queueEvent(request, env));
33 }
34 break;
35 }
36 case "/api/v1/events/bulk": {
37 if (request.method === "POST") {
38 return applyRateLimit(request, env, () => queueEvents(request, env));
39 }
40 break;
41 }
42 }
43
44 //the same request but with the hostname (and port) changed
45 return redirectToOrigin(request, env);
46 },
47};
48
49function redirectToOrigin(request: Request, env: Env) {

Callers 1

redirectToOriginFunction · 0.70

Calls 6

applyRateLimitFunction · 0.90
queueEventFunction · 0.90
queueEventsFunction · 0.90
queueingIsEnabledFunction · 0.85
redirectToOriginFunction · 0.85
logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…