Closed grempe closed 2 years ago
Tracker
In the javascript tracker code the post request is sending stringified JSON content with the content type header set to text/plain.
text/plain
https://github.com/tinybirdco/web-analytics-starter-kit/blob/3bd8da7c7bebb3e9f4773dc63e659e1dfbf8cebd/middleware/src/index.js#L94
This prevents the server from doing proper content negotiation. So for example the Next.js router will not automatically parse this incoming content to an Object.
https://nextjs.org/docs/api-routes/request-helpers
req.body - An object containing the body parsed by content-type, or null if no body was sent
Instead the Content-Type request header should be set to application/json
Content-Type
application/json
The POST call from the tracker should set the correct content-type.
Use the flock.js tracker to point towards a server that parses content correctly based on request content-type header.
content-type
No response
Fixed in version 1.2.2, just published.
Cool. Works. I've updated my code to remove the JSON.parse() and the bug ref.
JSON.parse()
https://github.com/grempe/nextjs-tinybird-example/blob/main/pages/api/tracking.ts#L87
Module
Tracker
Describe the Bug
In the javascript tracker code the post request is sending stringified JSON content with the content type header set to
text/plain
.https://github.com/tinybirdco/web-analytics-starter-kit/blob/3bd8da7c7bebb3e9f4773dc63e659e1dfbf8cebd/middleware/src/index.js#L94
This prevents the server from doing proper content negotiation. So for example the Next.js router will not automatically parse this incoming content to an Object.
https://nextjs.org/docs/api-routes/request-helpers
Instead the
Content-Type
request header should be set toapplication/json
Expected Behavior
The POST call from the tracker should set the correct content-type.
To Reproduce
Use the flock.js tracker to point towards a server that parses content correctly based on request
content-type
header.Details
No response