|
1 | 1 | import { WorkspaceWithUsers } from "@/lib/types"; |
2 | | -import { waitUntil } from "@vercel/functions"; |
3 | 2 | import { TokenCacheItem } from "../auth/token-cache"; |
4 | 3 | import { Session } from "../auth/utils"; |
5 | 4 | import { HTTP_MUTATION_METHODS, ROUTE_PATTERNS } from "./constants"; |
@@ -37,7 +36,7 @@ export function getRoutePattern(path: string): string { |
37 | 36 | return "unknown"; |
38 | 37 | } |
39 | 38 |
|
40 | | -export function captureRequestLog({ |
| 39 | +export async function captureRequestLog({ |
41 | 40 | req, |
42 | 41 | response, |
43 | 42 | workspace, |
@@ -69,33 +68,29 @@ export function captureRequestLog({ |
69 | 68 | const duration = Date.now() - startTime; |
70 | 69 | const responseClone = response.clone(); |
71 | 70 |
|
72 | | - waitUntil( |
73 | | - (async () => { |
74 | | - let requestBody = null; |
75 | | - let responseBody = null; |
| 71 | + let requestBody = null; |
| 72 | + let responseBody = null; |
76 | 73 |
|
77 | | - try { |
78 | | - requestBody = await req.json(); |
79 | | - } catch {} |
| 74 | + try { |
| 75 | + requestBody = await req.json(); |
| 76 | + } catch {} |
80 | 77 |
|
81 | | - try { |
82 | | - responseBody = await responseClone.json(); |
83 | | - } catch {} |
| 78 | + try { |
| 79 | + responseBody = await responseClone.json(); |
| 80 | + } catch {} |
84 | 81 |
|
85 | | - await recordApiLog({ |
86 | | - workspaceId: workspace.id, |
87 | | - method: req.method, |
88 | | - path: url.pathname, |
89 | | - routePattern, |
90 | | - statusCode: response.status, |
91 | | - duration, |
92 | | - userAgent: requestHeaders.get("user-agent"), |
93 | | - requestBody, |
94 | | - responseBody, |
95 | | - tokenId: token?.id ?? null, |
96 | | - userId: session?.user?.id ?? null, |
97 | | - requestType: "api", |
98 | | - }); |
99 | | - })(), |
100 | | - ); |
| 82 | + return await recordApiLog({ |
| 83 | + workspaceId: workspace.id, |
| 84 | + method: req.method, |
| 85 | + path: url.pathname, |
| 86 | + routePattern, |
| 87 | + statusCode: response.status, |
| 88 | + duration, |
| 89 | + userAgent: requestHeaders.get("user-agent"), |
| 90 | + requestBody, |
| 91 | + responseBody, |
| 92 | + tokenId: token?.id ?? null, |
| 93 | + userId: session?.user?.id ?? null, |
| 94 | + requestType: "api", |
| 95 | + }); |
101 | 96 | } |
0 commit comments