Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

練習問題の回答 #1467

Open
wants to merge 2 commits into
base: master-2020
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<body>
<h1>どちらが食べたいですか?</h1>
<form method="post" action="/enquetes/yaki-shabu">
<input type="text" name="name" />
<input type="radio" name="yaki-shabu" value="焼き肉" /> 焼き肉
<input type="radio" name="yaki-shabu" value="しゃぶしゃぶ" /> しゃぶしゃぶ
<button type="submit">投稿</button>
Expand Down
8 changes: 5 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ const server = http.createServer((req, res) => {
req.on('data', (chunk) => {
rawData = rawData + chunk;
}).on('end', () => {
const decoded = decodeURIComponent(rawData);
console.info('[' + now + '] 投稿: ' + decoded);
const qs = require('querystring');
const answer = qs.parse(rawData);
const body = answer['name'] + 'さんは' + answer['yaki-shabu'] + 'に投票しました';
console.info('[' + now + '] 投稿: ' + body);
res.write('<!DOCTYPE html><html lang="ja"><body><h1>' +
decoded + 'が投稿されました</h1></body></html>');
body + '</h1></body></html>');
res.end();
});
break;
Expand Down