質問編集履歴
3
現状報告の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
### 2020/07/26現在
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
まだ解決はしていません。
|
6
|
+
|
7
|
+
Linux環境で動作確認ができましたので、Windows環境の問題だと思います。
|
8
|
+
|
9
|
+
何かしらお気づきの点がございましたらコメントをよろしくお願いいたします。
|
10
|
+
|
11
|
+
|
12
|
+
|
1
13
|
### 前提・実現したいこと
|
2
14
|
|
3
15
|
|
@@ -262,6 +274,12 @@
|
|
262
274
|
|
263
275
|
- create database secret_board;でデーターベースを作成
|
264
276
|
|
277
|
+
- FirefoxでもGoogle Chromeでも動作は同じ状況
|
278
|
+
|
279
|
+
- node-postgresモジュールのサンプルを実行しましたが、コンソールに何も表示されません。
|
280
|
+
|
281
|
+
[Connecting | node-postgres](https://node-postgres.com/features/connecting)
|
282
|
+
|
265
283
|
|
266
284
|
|
267
285
|
netstatというコマンドでは以下のように出ます。
|
@@ -282,11 +300,23 @@
|
|
282
300
|
|
283
301
|
|
284
302
|
|
303
|
+
#### PostgreSQL Portable
|
304
|
+
|
305
|
+
|
306
|
+
|
285
307
|
PostgreSQL Portableという別のものも試しましたが、やはりnode.jsへのアクセスのところでうまくいきませんでした。
|
286
308
|
|
287
309
|
コマンド画面やコマンドプロンプトからのログイン、データーベースの作成はできました。
|
288
310
|
|
311
|
+
|
312
|
+
|
313
|
+
#### Vagrant + Ubuntu環境で動作確認(2020/07/26)
|
314
|
+
|
289
|
-
|
315
|
+
- 同じソースを実行してみたところデーターベースに保存できました。
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
|
290
320
|
|
291
321
|
|
292
322
|
|
2
posts-handler.jsのソースを追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -72,6 +72,8 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
+
#### post.js
|
76
|
+
|
75
77
|
[intro-curriculum-3022/post.js at master-2020 · progedu/intro-curriculum-3022](https://github.com/progedu/intro-curriculum-3022/blob/master-2020/lib/post.js)
|
76
78
|
|
77
79
|
```javascript
|
@@ -138,6 +140,118 @@
|
|
138
140
|
|
139
141
|
|
140
142
|
|
143
|
+
#### posts-handler.js
|
144
|
+
|
145
|
+
[intro-curriculum-3022/posts-handler.js at master-2020 · progedu/intro-curriculum-3022](https://github.com/progedu/intro-curriculum-3022/blob/master-2020/lib/posts-handler.js)
|
146
|
+
|
147
|
+
```javascript
|
148
|
+
|
149
|
+
'use strict';
|
150
|
+
|
151
|
+
const pug = require('pug');
|
152
|
+
|
153
|
+
const util = require('./handler-util');
|
154
|
+
|
155
|
+
const Post = require('./post');
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
function handle(req, res) {
|
160
|
+
|
161
|
+
switch (req.method) {
|
162
|
+
|
163
|
+
case 'GET':
|
164
|
+
|
165
|
+
res.writeHead(200, {
|
166
|
+
|
167
|
+
'Content-Type': 'text/html; charset=utf-8'
|
168
|
+
|
169
|
+
});
|
170
|
+
|
171
|
+
Post.findAll().then((posts) => {
|
172
|
+
|
173
|
+
res.end(pug.renderFile('./views/posts.pug', {
|
174
|
+
|
175
|
+
posts: posts
|
176
|
+
|
177
|
+
}));
|
178
|
+
|
179
|
+
});
|
180
|
+
|
181
|
+
break;
|
182
|
+
|
183
|
+
case 'POST':
|
184
|
+
|
185
|
+
let body = [];
|
186
|
+
|
187
|
+
req.on('data', (chunk) => {
|
188
|
+
|
189
|
+
body.push(chunk);
|
190
|
+
|
191
|
+
}).on('end', () => {
|
192
|
+
|
193
|
+
body = Buffer.concat(body).toString();
|
194
|
+
|
195
|
+
const decoded = decodeURIComponent(body);
|
196
|
+
|
197
|
+
const content = decoded.split('content=')[1];
|
198
|
+
|
199
|
+
console.info('投稿されました: ' + content);
|
200
|
+
|
201
|
+
Post.create({
|
202
|
+
|
203
|
+
content: content,
|
204
|
+
|
205
|
+
trackingCookie: null,
|
206
|
+
|
207
|
+
postedBy: req.user
|
208
|
+
|
209
|
+
}).then(() => {
|
210
|
+
|
211
|
+
handleRedirectPosts(req, res);
|
212
|
+
|
213
|
+
});
|
214
|
+
|
215
|
+
});
|
216
|
+
|
217
|
+
break;
|
218
|
+
|
219
|
+
default:
|
220
|
+
|
221
|
+
util.handleBadRequest(req, res);
|
222
|
+
|
223
|
+
break;
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
function handleRedirectPosts(req, res) {
|
232
|
+
|
233
|
+
res.writeHead(303, {
|
234
|
+
|
235
|
+
'Location': '/posts'
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
res.end();
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
module.exports = {
|
246
|
+
|
247
|
+
handle
|
248
|
+
|
249
|
+
};
|
250
|
+
|
251
|
+
```
|
252
|
+
|
253
|
+
|
254
|
+
|
141
255
|
### 試したこと
|
142
256
|
|
143
257
|
|
1
URLをMarkdown記法に変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
掲示板のソースはここにあるものです。
|
16
16
|
|
17
|
-
https://github.com/progedu/intro-curriculum-3022/tree/master-2020
|
17
|
+
[progedu/intro-curriculum-3022 at master-2020](https://github.com/progedu/intro-curriculum-3022/tree/master-2020)
|
18
18
|
|
19
19
|
N予備校の教材としてはVirtualBox+Vagrant+Ubuntuを前提なのですが、Windowsで動作させたいと思っています。
|
20
20
|
|
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
以下が掲示板のソースコードです。
|
66
66
|
|
67
|
-
https://github.com/progedu/intro-curriculum-3022/tree/master-2020
|
67
|
+
[progedu/intro-curriculum-3022 at master-2020](https://github.com/progedu/intro-curriculum-3022/tree/master-2020)
|
68
68
|
|
69
69
|
|
70
70
|
|
@@ -72,7 +72,7 @@
|
|
72
72
|
|
73
73
|
|
74
74
|
|
75
|
-
https://github.com/progedu/intro-curriculum-3022/blob/master-2020/lib/post.js
|
75
|
+
[intro-curriculum-3022/post.js at master-2020 · progedu/intro-curriculum-3022](https://github.com/progedu/intro-curriculum-3022/blob/master-2020/lib/post.js)
|
76
76
|
|
77
77
|
```javascript
|
78
78
|
|
@@ -180,11 +180,11 @@
|
|
180
180
|
|
181
181
|
- postgresql-12.3-2-windows-x64
|
182
182
|
|
183
|
-
https://www.postgresql.org/download/
|
183
|
+
[PostgreSQL: Downloads](https://www.postgresql.org/download/)
|
184
184
|
|
185
185
|
- PostgreSQL Portable(10.1.1)
|
186
186
|
|
187
|
-
https://sourceforge.net/projects/postgresqlportable/files/v10.1.1/
|
187
|
+
[PostgreSQL Portable - Browse /v10.1.1 at SourceForge.net](https://sourceforge.net/projects/postgresqlportable/files/v10.1.1/)
|
188
188
|
|
189
189
|
- node.js(v14.3.0)
|
190
190
|
|