Skip to content
File

Blob: src/workerd/api/node/tests/http-server-nodejs-global-test.js

javascript24 lines
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
4import http from 'node:http';
5import { strictEqual } from 'node:assert';
6import { httpServerHandler } from 'cloudflare:node';
7 
8const 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.
15export default httpServerHandler(server);
16strictEqual(typeof server.address().port, 'number');
17 
18export 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};