(request: Request, env: Env, ctx: ExecutionContext)
| 12 | |
| 13 | export default { |
| 14 | async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> { |
| 15 | const url = new URL(request.url); |
| 16 | const route = routeUrl(url, env); |
| 17 | |
| 18 | switch (route.type) { |
| 19 | case 'management': { |
| 20 | return handleManagementRequest(request, env, ctx); |
| 21 | } |
| 22 | case 'tunnel': { |
| 23 | console.log(`Handling tunnel request for ${route.name}`); |
| 24 | |
| 25 | const id = await env.tunnelIds.get(route.name); |
| 26 | |
| 27 | if (!id) { |
| 28 | return new Response('Not Found', { status: 404 }); |
| 29 | } |
| 30 | |
| 31 | const tunnel = env.connections.get(env.connections.idFromString(id)); |
| 32 | return tunnel.fetch(request); |
| 33 | } |
| 34 | case 'not_found': { |
| 35 | return new Response('Not Found', { status: 404 }); |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return new Response('Not Found', { status: 404 }); |
| 40 | }, |
| 41 | }; |
| 42 | |
| 43 | type RouteDecision = |
no test coverage detected
searching dependent graphs…