File tree 1 file changed +99
-0
lines changed
1 file changed +99
-0
lines changed Original file line number Diff line number Diff line change 1
1
# ハンズオン目次
2
2
3
+ ## Hello, chibivite!
4
+
5
+ ``` ts
6
+ const app = connect ()
7
+
8
+ app .use (function () {
9
+ return ' Hello, chibivite!'
10
+ })
11
+
12
+ app .listen ()
13
+ ```
14
+
15
+ ``` sh
16
+ node index.mjs
17
+ ```
18
+
19
+ ## ` index.html ` へのアクセス
20
+
21
+ ``` html
22
+ <!DOCTYPE html>
23
+ <html lang =" en" >
24
+ <head >
25
+ <meta charset =" UTF-8" />
26
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
27
+ <title >chibivite</title >
28
+ </head >
29
+ <body >
30
+ <h1 >Hello, chibivite!</h1 >
31
+ </body >
32
+ </html >
33
+ ```
34
+
35
+ ``` ts
36
+ import fs from ' fs/promises'
37
+ import connect from
38
+
39
+ const app = connect ()
40
+
41
+ app .use (async function () {
42
+ const content = await fs .readFile (' ./index.html' , ' utf-8' )
43
+ return content
44
+ })
45
+
46
+ app .listen ()
47
+ ```
48
+
49
+ ``` sh
50
+ node index.mjs
51
+ ```
52
+
53
+ ## JavaScript へのアクセス
54
+
55
+ ``` html
56
+ <!DOCTYPE html>
57
+ <html lang =" en" >
58
+ <head >
59
+ <meta charset =" UTF-8" />
60
+ <meta name =" viewport" content =" width=device-width, initial-scale=1.0" />
61
+ <title >chibivite</title >
62
+ </head >
63
+ <body >
64
+ <h1 >Hello, chibivite!</h1 >
65
+ <script type =" module" src =" /src/index.mjs" ></script >
66
+ </body >
67
+ </html >
68
+ ```
69
+
70
+ ``` js
71
+ console .log (' Hello, chibivite!' )
72
+ ```
73
+
74
+ ``` ts
75
+ import fs from ' fs/promises'
76
+ import connect from
77
+
78
+ const app = connect ()
79
+
80
+ app .use (async function (req , _ , next ) {
81
+ if (req .path .endsWith (' .mjs' )) {
82
+ const content = await fs .readFile (' ./src/index.mjs' , ' utf-8' )
83
+ return content
84
+ }
85
+ next ()
86
+ })
87
+
88
+ app .use (async function () {
89
+ const content = await fs .readFile (' ./index.html' , ' utf-8' )
90
+ return content
91
+ })
92
+
93
+ app .listen ()
94
+ ```
95
+
96
+ ``` sh
97
+ node index.mjs
98
+ ```
99
+
100
+ ---
101
+
3
102
- ツールのセットアップ
4
103
- プロジェクトのセットアップ
5
104
- Hello, chibivite!
You can’t perform that action at this time.
0 commit comments