質問編集履歴

1

追記

2019/12/08 08:31

投稿

lin.ming
lin.ming

スコア50

test CHANGED
File without changes
test CHANGED
@@ -95,3 +95,79 @@
95
95
  バージョンの問題でしょうか?
96
96
 
97
97
  知見のある方、どうぞよろしくお願いします。
98
+
99
+
100
+
101
+ 追記
102
+
103
+ 以下のコードを試しました。
104
+
105
+ ```node.js
106
+
107
+ const http = require("http");
108
+
109
+ const express = require("express");
110
+
111
+ app = express();
112
+
113
+ const router = express.Router();
114
+
115
+ const { check, validationResult } = require('express-validator');
116
+
117
+
118
+
119
+ app.use("/", router);
120
+
121
+
122
+
123
+ router.get('/', (req, res) => {
124
+
125
+ res.writeHead(200, {
126
+
127
+ "Content-Type": "text/html"
128
+
129
+ });
130
+
131
+ let web = "<html><head></head>" +
132
+
133
+ '<body><form action = "/path" name ="form" method = "POST" />' +
134
+
135
+ '<input type = "text" name = "email" />' +
136
+
137
+ '<input type = "submit" name = "submit">' +
138
+
139
+ "</body>" +
140
+
141
+ "</html>"
142
+
143
+ res.write(web);
144
+
145
+ res.end();
146
+
147
+ });
148
+
149
+
150
+
151
+ router.post('/path', [check("email").isEmail()], (req, res) => {
152
+
153
+ const errors = validationResult(req);
154
+
155
+ if (!errors.isEmpty()) {
156
+
157
+ res.status(400).end();
158
+
159
+ return;
160
+
161
+ }
162
+
163
+ res.status(200).end();
164
+
165
+ });
166
+
167
+
168
+
169
+ app.listen(3000);
170
+
171
+ ```
172
+
173
+ コンパイルは通るのですが、メールアドレスを入力しても400エラーになります。