File tree Expand file tree Collapse file tree 2 files changed +20
-19
lines changed
docs/3-web-servers/06-get-post/_samples/forum Expand file tree Collapse file tree 2 files changed +20
-19
lines changed Original file line number Diff line number Diff line change 1+ <!doctype html>
2+ < html lang ="ja ">
3+ < head >
4+ < meta charset ="UTF-8 " />
5+ < title > Document</ title >
6+ </ head >
7+ < body >
8+ < ul >
9+ {messages}
10+ </ ul >
11+ < form action ="/send " method ="post ">
12+ < input name ="message " />
13+ < button > 送信</ button >
14+ </ form >
15+ </ body >
16+ </ html >
Original file line number Diff line number Diff line change @@ -7,29 +7,14 @@ const messages = [];
77app . use ( express . urlencoded ( { extended : true } ) ) ;
88
99app . get ( "/" , ( request , response ) => {
10- response . send ( `
11- <!doctype html>
12- <html lang="ja">
13- <head>
14- <meta charset="UTF-8" />
15- <title>Document</title>
16- </head>
17- <body>
18- <ul>
19- ${ messages . map ( ( message ) => `<li>${ message } </li>` ) . join ( "" ) }
20- </ul>
21- <form action="/send" method="post">
22- <input name="message" />
23- <button>送信</button>
24- </form>
25- </body>
26- </html>
27- ` ) ;
10+ const template = fs . readFileSync ( "index.html" ) ;
11+ const html = template . replace ( "{messages}" , messages . map ( ( msg ) => `<li>${ msg } </li>` ) . join ( "" ) ) ;
12+ response . send ( html ) ;
2813} ) ;
2914
3015app . post ( "/send" , ( request , response ) => {
3116 messages . push ( request . body . message ) ;
32- response . send ( "送信しました" ) ;
17+ response . send ( "<body> 送信しました</body> " ) ;
3318} ) ;
3419
3520app . listen ( 3000 ) ;
You can’t perform that action at this time.
0 commit comments