I am creating an API using CF functions for the first time.
Referring to the example, the result is normal, but the phrase “Your worker called response.clone()…” is output on the local console.
“Since a response. body readable-stream can only be read ONCE” is understand.
I don’t understand the error message “use new Response(response.body, response)
instead.”
I couldn’t find a clear answer in Googling and community either.
There is no response.clone within my code, and I don’t know how to apply it in “cloudflare functions”.
The execution environment is as follows.
wrangler version : 3.1.1
node version : 19.9.0
Below is my code run locally.
** command **
curl -H "Content-Type: application/json" -X POST http://localhost:8788/api/v1/signup -d '{"email":"mails","password":"paaaaass"}'
_middleware.js
const authorization = async ({ request, next, env }) => {
const url = new URL(request.url);
console.log('middleware url:', url);
let cookie = request.headers.get('cookie');
if (cookie) {
console.log('cookie:', cookie);
}
return next();
};
export const onRequest = [authorization];
functions/api/v1/signup
export async function onRequestPost(context) {
return await signupHandler(context);
}
async function signupHandler(context) {
const { request, response } = context;
const data = await request.json();
const { email, password } = data;
console.log(`email: ${email}, password: ${password}`);
return Response.json(data);
}
Result console.
⎔ Starting local server...
[mf:wrn] The latest compatibility date supported by the installed Cloudflare Workers Runtime is "2023-05-18",
but you've requested "2023-07-14". Falling back to "2023-05-18"...
[mf:inf] Ready on http://127.0.0.1:8788/
middleware url: URL {
}
Your worker called response.clone(), but did not read the body of both clones. This is wasteful, as it forces the system to buffer the entire response body in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the response headers and metadata (e.g. in order to be able to modify them), use `new Response(response.body, response)` instead.
email: mails, password: paaaaass
Your worker called response.clone(), but did not read the body of both clones. This is wasteful, as it forces the system to buffer the entire response body in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the response headers and metadata (e.g. in order to be able to modify them), use `new Response(response.body, response)` instead.
Your worker called response.clone(), but did not read the body of both clones. This is wasteful, as it forces the system to buffer the entire response body in memory, rather than streaming it through. This may cause your worker to be unexpectedly terminated for going over the memory limit. If you only meant to copy the response headers and metadata (e.g. in order to be able to modify them), use `new Response(response.body, response)` instead.
[mf:inf] POST /api/v1/signup 200 OK (29ms)