File
Blob: samples/nodejs-compat-http/worker.js
| 1 | import { get } from 'node:http'; |
| 2 | export default { |
| 3 | async fetch(request) { |
| 4 | const { promise, resolve } = Promise.withResolvers(); |
| 5 | get('http://example.com', { |
| 6 | headers: { |
| 7 | 'accept': 'text/plain', |
| 8 | } |
| 9 | }, (res) => { |
| 10 | let data = ''; |
| 11 | res.on('data', (chunk) => { |
| 12 | data += chunk; |
| 13 | }); |
| 14 | res.on('end', () => { |
| 15 | console.log('...', data); |
| 16 | resolve(new Response(data)); |
| 17 | }); |
| 18 | }); |
| 19 | return promise; |
| 20 | } |
| 21 | }; |