diff --git a/src/app/api/batch/route.ts b/src/app/api/batch/route.ts index 6feab06b6..aae14c96e 100644 --- a/src/app/api/batch/route.ts +++ b/src/app/api/batch/route.ts @@ -18,7 +18,20 @@ export async function POST(request: Request) { let index = 0; for (const data of body) { - const newRequest = new Request(request, { body: JSON.stringify(data) }); + // Recreate a fresh Request since `new Request(request)` will have the following error: + // > Cannot read private member #state from an object whose class did not declare it + + // Copy headers we received, ensure JSON content type, and avoid conflicting content-length + const headers = new Headers(request.headers); + headers.set('content-type', 'application/json'); + headers.delete('content-length'); + + const newRequest = new Request(request.url, { + method: 'POST', + headers, + body: JSON.stringify(data), + }); + const response = await send.POST(newRequest); if (!response.ok) { diff --git a/src/queries/sql/pageviews/getPageviewExpandedMetrics.ts b/src/queries/sql/pageviews/getPageviewExpandedMetrics.ts index 938b28acd..986d7d5a5 100644 --- a/src/queries/sql/pageviews/getPageviewExpandedMetrics.ts +++ b/src/queries/sql/pageviews/getPageviewExpandedMetrics.ts @@ -86,7 +86,7 @@ async function relationalQuery( sum(${getTimestampDiffSQL('t.min_time', 't.max_time')}) as "totaltime" from ( select - ${column} name, + ${column} as name, website_event.session_id, website_event.visit_id, count(*) as "c", @@ -101,7 +101,7 @@ async function relationalQuery( and website_event.event_type != 2 ${excludeDomain} ${filterQuery} - group by name, website_event.session_id, website_event.visit_id + group by ${column}, website_event.session_id, website_event.visit_id ) as t where name != '' group by name