Skip to content

Commit 43e1810

Browse files
committed
1 parent 1a2f5ef commit 43e1810

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

deno_http.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@ import { serve } from "https://deno.land/[email protected]/http/server.ts";
22

33
const port = 3000;
44
const s = serve({ port });
5+
const body = new TextEncoder().encode("Hello World");
56

67
console.log("deno_http listen on", port);
78
for await (const req of s) {
8-
req.respond({ body: "Hello World\n" });
9+
const res = {
10+
body,
11+
headers: new Headers(),
12+
};
13+
res.headers.set("Date", new Date().toUTCString());
14+
res.headers.set("Connection", "keep-alive");
15+
req.respond(res).catch(() => {});
916
}

node_http.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ const http = require("http");
33
const hostname = "127.0.0.1";
44
const port = 3000;
55

6-
const server = http.createServer((req, res) => {
7-
res.end("Helloi World!");
8-
});
9-
10-
server.listen(port, hostname, () => {
6+
http.createServer((req, res) => {
7+
res.end("Hello World");
8+
}).listen(port, hostname, () => {
119
console.log("node listening on:", port);
1210
});

0 commit comments

Comments
 (0)