File
Blob: src/workerd/api/node/tests/http-server-nodejs-global-test.js
| 1 | // Copyright (c) 2025 Cloudflare, Inc. |
| 2 | // Licensed under the Apache 2.0 license found in the LICENSE file or at: |
| 3 | // https://opensource.org/licenses/Apache-2.0 |
| 4 | import http from 'node:http'; |
| 5 | import { strictEqual } from 'node:assert'; |
| 6 | import { httpServerHandler } from 'cloudflare:node'; |
| 7 | |
| 8 | const server = http.createServer((req, res) => { |
| 9 | res.end('hello world'); |
| 10 | }); |
| 11 | |
| 12 | // The server can be started by passing it to the httpServerHandler |
| 13 | // which will call the server's listen method if it hasn't already |
| 14 | // been called. |
| 15 | export default httpServerHandler(server); |
| 16 | strictEqual(typeof server.address().port, 'number'); |
| 17 | |
| 18 | export const checkItWorks = { |
| 19 | async test(_ctrl, env) { |
| 20 | const resp = await env.SUBREQUEST.fetch('http://example.com'); |
| 21 | strictEqual(await resp.text(), 'hello world'); |
| 22 | }, |
| 23 | }; |