storyblok / storyblok-astro

Astro SDK for Storyblok CMS
159 stars 29 forks source link

Clone the request in the live preview middleware before consuming it #845

Closed dominik-erni closed 2 months ago

dominik-erni commented 2 months ago

It would be nice when the live preview middleware would clone the request before consuming it with request.json(). In our project we have a custom middleware which for general logging which tries to clone the request before consuming it to log the body to the console, but this now fails because the request has already been consumed.

Link


Expected Behavior

Consuming the request after this live preview middleware consumed it should not fail.

Current Behavior

Consuming the request after this live preview middleware consumed it fails currently.

Steps to Reproduce

dominik-erni commented 2 months ago

Or can't you send this "is_storyblok_preview" as http request header from Storyblok Visual Editor, then you don0t need to call request.json() in this live preview middleware and the problem should be gone

dominik-erni commented 2 months ago

I tested it with changing the line in the live preview middleware dist to: const requestBody = await request.clone().json();

Then our POST API calls work again

dipankarmaikap commented 2 months ago

@dominik-erni Thank you for identifying the issue with the POST request URL and suggesting the solution of making a copy of the request.

I'm happy to inform you that we have added the fix and optimized the middleware further. The changes are currently under review and will be merged soon.

We appreciate your patience and will update you once the fix is released.

github-actions[bot] commented 2 months ago

:tada: This issue has been resolved in version 4.1.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: