Skip to content
File

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

javascript26 lines
1// Copyright (c) 2017-2022 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 
5// This is a sidecar that runs alongside the http-client-nodejs-test.* tests.
6// It is executed using the appropriate Node.js version defined in build/deps/nodejs.MODULE.bazel.
7const http = require('node:http');
8 
9function reportAddress(server) {
10 const address = server.address();
11 console.info(`Listening on ${address.address}:${address.port}`);
12}
13 
14const pongServer = http.createServer((req, res) => {
15 req.resume();
16 req.on('end', () => {
17 res.writeHead(200);
18 res.end('pong');
19 });
20});
21pongServer.listen(
22 process.env.PONG_SERVER_PORT,
23 process.env.SIDECAR_HOSTNAME,
24 () => reportAddress(pongServer)
25);