Skip to content

Commit d4188fd

Browse files
committed
Go over Chapter 20
1 parent 357c47f commit d4188fd

7 files changed

Lines changed: 97 additions & 145 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/html/ejs.js
1414
/code/chapter/*
1515
/code/chapter_info.js
16-
/code/file_server.js
16+
/code/file_server.mjs
1717
/code/skillsharing.zip
1818
/code/solutions/20_3_a_public_space_on_the_web.zip
1919
/code/skillsharing/*

18_http.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Then the server responds, through that same connection.
3232

3333
```{lang: http}
3434
HTTP/1.1 200 OK
35-
Content-Length: 140596
35+
Content-Length: 87320
3636
Content-Type: text/html
3737
Last-Modified: Fri, 13 Oct 2023 10:05:41 GMT
3838
@@ -81,14 +81,14 @@ Status codes starting with a 2 indicate that the request succeeded. Codes starti
8181
The first line of a request or response may be followed by any number of _((header))s_. These are lines in the form `name: value` that specify extra information about the request or response. These headers were part of the example ((response)):
8282

8383
```{lang: null}
84-
Content-Length: 140596
84+
Content-Length: 87320
8585
Content-Type: text/html
8686
Last-Modified: Fri, 13 Oct 2023 10:05:41 GMT
8787
```
8888

8989
{{index "Content-Length header", "Content-Type header", "Last-Modified header"}}
9090

91-
This tells us the size and type of the response document. In this case, it is an HTML document of 140,596 bytes. It also tells us when that document was last modified.
91+
This tells us the size and type of the response document. In this case, it is an HTML document of 87,320 bytes. It also tells us when that document was last modified.
9292

9393
The client and server are free to decide what ((header))s to include in their ((request))s or ((response))s. But some of them are necessary for things to work. For example, without a `Content-Type` header in the response, the browser won't know how to display the document.
9494

20_node.md

Lines changed: 85 additions & 133 deletions
Large diffs are not rendered by default.

code/solutions/20_1_search_tool.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const {statSync, readdirSync, readFileSync} = require("fs");
1+
import {statSync, readdirSync, readFileSync} from "node:fs";
22

33
let searchTerm = new RegExp(process.argv[2]);
44

code/solutions/20_2_directory_creation.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// This code won't work on its own, but is also included in the
22
// code/file_server.js file, which defines the whole system.
33

4-
const {mkdir} = require("fs").promises;
4+
import {mkdir} from "node:fs/promises";
55

66
methods.MKCOL = async function(request) {
77
let path = urlPath(request.url);

src/chapter_info.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,18 @@ for (let file of fs.readdirSync(".").sort()) {
7676
let nodeInfo = "// Node exercises can not be ran in the browser,\n// but you can look at their solution here.\n";
7777
if (chapter.number == 20) chapter.exercises = [
7878
{name: "Search tool",
79-
file: "code/solutions/20_1_search_tool.js",
79+
file: "code/solutions/20_1_search_tool.mjs",
8080
number: 1,
8181
type: "js",
8282
code: nodeInfo,
83-
solution: fs.readFileSync("code/solutions/20_1_search_tool.js", "utf8")
83+
solution: fs.readFileSync("code/solutions/20_1_search_tool.mjs", "utf8")
8484
},
8585
{name: "Directory creation",
86-
file: "code/solutions/20_2_directory_creation.js",
86+
file: "code/solutions/20_2_directory_creation.mjs",
8787
number: 2,
8888
type: "js",
8989
code: nodeInfo,
90-
solution: fs.readFileSync("code/solutions/20_2_directory_creation.js", "utf8")
90+
solution: fs.readFileSync("code/solutions/20_2_directory_creation.mjs", "utf8")
9191
},
9292
{name: "A public space on the web",
9393
file: "code/solutions/20_3_a_public_space_on_the_web.zip",

src/client/code.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class CodeSandbox {
111111
let link = document.querySelector("#download")
112112
link.setAttribute("download", "solution" + value + ".js")
113113
if (/\.zip$/.test(exercise.file))
114-
link.href = exercise.file
114+
link.href = "../" + exercise.file
115115
else
116116
link.href = "data:text/plain;charset=UTF-8," + encodeURIComponent(exercise.solution)
117117
}
@@ -225,7 +225,7 @@ function getChapter(number) {
225225
function addItem(container, link) {
226226
let li = container.appendChild(document.createElement("li"))
227227
let a = li.appendChild(document.createElement("a"))
228-
a.href = link
228+
a.href = "../" + link
229229
a.textContent = link.replace(/^code\//, "")
230230
}
231231

0 commit comments

Comments
 (0)