Skip to content

Commit 5f46450

Browse files
committed
address pr reviews
1 parent 4012416 commit 5f46450

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

src/content/docs/workers/runtime-apis/nodejs/http.mdx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ The `cloudflare.cf` property contains [Cloudflare-specific request properties](/
173173
The following differences exist between the Workers implementation and Node.js:
174174

175175
- Trailer headers are not supported
176-
- The `socket` attribute only contains the following properties: `encrypted`, `remoteFamily`, `remoteAddress`, `remotePort`, `localAddress`, `localPort`, and `destroy()` method
177-
- The `socket` attribute does not extend from `net.Socket`
176+
- The `socket` attribute **does not extend from `net.Socket`** and only contains the following properties: `encrypted`, `remoteFamily`, `remoteAddress`, `remotePort`, `localAddress`, `localPort`, and `destroy()` method
178177

179178
## createServer
180179

@@ -198,7 +197,7 @@ export default httpServerHandler({ port: 8080 });
198197
The `httpServerHandler` function integrates Node.js HTTP servers with the Cloudflare Workers request model. When a request arrives at your Worker, the handler automatically routes it to your Node.js server running on the specified port. This bridge allows you to use familiar Node.js server patterns while benefiting from the Workers runtime environment, including automatic scaling, edge deployment, and integration with other Cloudflare services.
199198

200199
:::note
201-
Failing to call `close()` on an HTTP server may result in the server being leaked. To prevent this, call `close()` when you're done with the server, or use explicit resource management:
200+
Failing to call `close()` on an HTTP server may result in the server persisting until the worker is destroyed. In most cases, this is not an issue since servers typically live for the lifetime of the worker. However, if you need to create multiple servers during a worker's lifetime or want explicit lifecycle control (such as in test scenarios), call `close()` when you're done with the server, or use explicit resource management:
202201

203202
```js
204203
import { createServer } from 'node:http';
@@ -243,24 +242,13 @@ An implementation of the Node.js [`http.ServerResponse`](https://nodejs.org/docs
243242

244243
The `ServerResponse` class represents the server-side response object that is passed to request handlers. It provides methods for writing response headers and body data, and extends the Node.js `Writable` stream class.
245244

246-
```js
247-
import { createServer, ServerResponse } from 'node:http';
248-
import { ok } from 'node:assert';
249-
250-
const server = createServer((req, res) => {
251-
ok(res instanceof ServerResponse);
252-
res.statusCode = 200;
253-
res.setHeader('Content-Type', 'text/html');
254-
res.write('<h1>Hello World</h1>');
255-
res.end();
256-
});
257-
```
258-
259245
```js
260246
import { createServer } from 'node:http';
261247
import { httpServerHandler } from 'cloudflare:node';
262248

263249
const server = createServer((req, res) => {
250+
ok(res instanceof ServerResponse);
251+
264252
// Set multiple headers at once
265253
res.writeHead(200, {
266254
'Content-Type': 'application/json',

src/content/docs/workers/runtime-apis/nodejs/https.mdx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,19 @@ The `Server` class represents an HTTPS server and provides methods for handling
157157

158158
```js
159159
import { Server } from 'node:https';
160+
import { httpServerHandler } from 'cloudflare:node';
160161

161162
const server = new Server((req, res) => {
162163
res.writeHead(200, { 'Content-Type': 'application/json' });
163164
res.end(JSON.stringify({ message: 'Hello from HTTPS Server!' }));
164165
});
166+
server.listen(8080);
167+
export default httpServerHandler({ port: 8080 });
165168
```
166169

167170
The following differences exist between the Workers implementation and Node.js:
168171

169172
- Connection management methods such as `closeAllConnections()` and `closeIdleConnections()` are not implemented
170173
- Only `listen()` variants with a port number or no parameters are supported: `listen()`, `listen(0, callback)`, `listen(callback)`, etc.
171174
- The following server options are not supported: `maxHeaderSize`, `insecureHTTPParser`, `keepAliveTimeout`, `connectionsCheckingInterval`
172-
- TLS/SSL-specific options such as `ca`, `cert`, `key`, `pfx`, `rejectUnauthorized`, `secureProtocol` are not supported in the Workers environment
175+
- TLS/SSL-specific options such as `ca`, `cert`, `key`, `pfx`, `rejectUnauthorized`, `secureProtocol` are not supported in the Workers environment

0 commit comments

Comments
 (0)