mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 09:08:16 +08:00
add uuid into path
This commit is contained in:
28
functions/sample/http2.ts
Normal file
28
functions/sample/http2.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
interface Env {
|
||||
KV: KVNamespace;
|
||||
}
|
||||
|
||||
export const onRequest: PagesFunction<Env> = async (context) => {
|
||||
let count = 0;
|
||||
console.log('test11', Date.now());
|
||||
await new Promise((resolve, rej) => {
|
||||
setTimeout(() => {
|
||||
resolve('');
|
||||
}, 100);
|
||||
});
|
||||
console.log('test11', Date.now());
|
||||
const transformStream =
|
||||
context.request.body?.pipeThrough(new TextDecoderStream()).pipeThrough(
|
||||
new TransformStream({
|
||||
transform(chunk, controller) {
|
||||
console.log('test', Date.now());
|
||||
controller.enqueue(
|
||||
new TextEncoder().encode(`${chunk} + ${count++} ${new Date()}`)
|
||||
);
|
||||
},
|
||||
})
|
||||
) || 'default';
|
||||
return new Response(transformStream, {
|
||||
headers: { 'content-type': 'text/plain' },
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user