質問編集履歴
3
現状報告の追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
### 2020/07/26現在
|
2
|
+
|
3
|
+
まだ解決はしていません。
|
4
|
+
Linux環境で動作確認ができましたので、Windows環境の問題だと思います。
|
5
|
+
何かしらお気づきの点がございましたらコメントをよろしくお願いいたします。
|
6
|
+
|
1
7
|
### 前提・実現したいこと
|
2
8
|
|
3
9
|
Node.jsとPostgreSQLを使って、ローカルのWindows10マシンで動く掲示板を作っています。
|
@@ -130,6 +136,9 @@
|
|
130
136
|
- PostgreSQLはインストールしてPgAdmin 4から起動、ブラウザで動作
|
131
137
|
- コマンドプロンプトからpsql -U postgresでコマンド画面起動
|
132
138
|
- create database secret_board;でデーターベースを作成
|
139
|
+
- FirefoxでもGoogle Chromeでも動作は同じ状況
|
140
|
+
- node-postgresモジュールのサンプルを実行しましたが、コンソールに何も表示されません。
|
141
|
+
[Connecting | node-postgres](https://node-postgres.com/features/connecting)
|
133
142
|
|
134
143
|
netstatというコマンドでは以下のように出ます。
|
135
144
|
netstat | grep 5432
|
@@ -140,10 +149,16 @@
|
|
140
149
|
TCP [::1]:5432 (私のPC名):4247 ESTABLISHED
|
141
150
|
```
|
142
151
|
|
152
|
+
#### PostgreSQL Portable
|
153
|
+
|
143
154
|
PostgreSQL Portableという別のものも試しましたが、やはりnode.jsへのアクセスのところでうまくいきませんでした。
|
144
155
|
コマンド画面やコマンドプロンプトからのログイン、データーベースの作成はできました。
|
145
|
-
掲示板の表示は、FirefoxでもChromeでも同じ状況です。
|
146
156
|
|
157
|
+
#### Vagrant + Ubuntu環境で動作確認(2020/07/26)
|
158
|
+
- 同じソースを実行してみたところデーターベースに保存できました。
|
159
|
+
|
160
|
+
|
161
|
+
|
147
162
|
### 補足情報(FW/ツールのバージョンなど)
|
148
163
|
- postgresql-12.3-2-windows-x64
|
149
164
|
[PostgreSQL: Downloads](https://www.postgresql.org/download/)
|
2
posts-handler.jsのソースを追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -35,6 +35,7 @@
|
|
35
35
|
|
36
36
|
これ以外でもN予備校のPostgreSQLを利用したプログラムが同じように動作しない状況です。
|
37
37
|
|
38
|
+
#### post.js
|
38
39
|
[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)
|
39
40
|
```javascript
|
40
41
|
'use strict';
|
@@ -68,6 +69,62 @@
|
|
68
69
|
module.exports = Post;
|
69
70
|
```
|
70
71
|
|
72
|
+
#### posts-handler.js
|
73
|
+
[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)
|
74
|
+
```javascript
|
75
|
+
'use strict';
|
76
|
+
const pug = require('pug');
|
77
|
+
const util = require('./handler-util');
|
78
|
+
const Post = require('./post');
|
79
|
+
|
80
|
+
function handle(req, res) {
|
81
|
+
switch (req.method) {
|
82
|
+
case 'GET':
|
83
|
+
res.writeHead(200, {
|
84
|
+
'Content-Type': 'text/html; charset=utf-8'
|
85
|
+
});
|
86
|
+
Post.findAll().then((posts) => {
|
87
|
+
res.end(pug.renderFile('./views/posts.pug', {
|
88
|
+
posts: posts
|
89
|
+
}));
|
90
|
+
});
|
91
|
+
break;
|
92
|
+
case 'POST':
|
93
|
+
let body = [];
|
94
|
+
req.on('data', (chunk) => {
|
95
|
+
body.push(chunk);
|
96
|
+
}).on('end', () => {
|
97
|
+
body = Buffer.concat(body).toString();
|
98
|
+
const decoded = decodeURIComponent(body);
|
99
|
+
const content = decoded.split('content=')[1];
|
100
|
+
console.info('投稿されました: ' + content);
|
101
|
+
Post.create({
|
102
|
+
content: content,
|
103
|
+
trackingCookie: null,
|
104
|
+
postedBy: req.user
|
105
|
+
}).then(() => {
|
106
|
+
handleRedirectPosts(req, res);
|
107
|
+
});
|
108
|
+
});
|
109
|
+
break;
|
110
|
+
default:
|
111
|
+
util.handleBadRequest(req, res);
|
112
|
+
break;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
function handleRedirectPosts(req, res) {
|
117
|
+
res.writeHead(303, {
|
118
|
+
'Location': '/posts'
|
119
|
+
});
|
120
|
+
res.end();
|
121
|
+
}
|
122
|
+
|
123
|
+
module.exports = {
|
124
|
+
handle
|
125
|
+
};
|
126
|
+
```
|
127
|
+
|
71
128
|
### 試したこと
|
72
129
|
|
73
130
|
- PostgreSQLはインストールしてPgAdmin 4から起動、ブラウザで動作
|
1
URLをMarkdown記法に変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
PostgreSQLに掲示板の投稿内容を保存して表示したいです。
|
7
7
|
|
8
8
|
掲示板のソースはここにあるものです。
|
9
|
-
https://github.com/progedu/intro-curriculum-3022/tree/master-2020
|
9
|
+
[progedu/intro-curriculum-3022 at master-2020](https://github.com/progedu/intro-curriculum-3022/tree/master-2020)
|
10
10
|
N予備校の教材としてはVirtualBox+Vagrant+Ubuntuを前提なのですが、Windowsで動作させたいと思っています。
|
11
11
|
N予備校では動作保証外なので、こちらで質問させていただいています。
|
12
12
|
|
@@ -31,11 +31,11 @@
|
|
31
31
|
### 該当のソースコード
|
32
32
|
|
33
33
|
以下が掲示板のソースコードです。
|
34
|
-
https://github.com/progedu/intro-curriculum-3022/tree/master-2020
|
34
|
+
[progedu/intro-curriculum-3022 at master-2020](https://github.com/progedu/intro-curriculum-3022/tree/master-2020)
|
35
35
|
|
36
36
|
これ以外でもN予備校のPostgreSQLを利用したプログラムが同じように動作しない状況です。
|
37
37
|
|
38
|
-
https://github.com/progedu/intro-curriculum-3022/blob/master-2020/lib/post.js
|
38
|
+
[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)
|
39
39
|
```javascript
|
40
40
|
'use strict';
|
41
41
|
const Sequelize = require('sequelize');
|
@@ -89,9 +89,9 @@
|
|
89
89
|
|
90
90
|
### 補足情報(FW/ツールのバージョンなど)
|
91
91
|
- postgresql-12.3-2-windows-x64
|
92
|
-
https://www.postgresql.org/download/
|
92
|
+
[PostgreSQL: Downloads](https://www.postgresql.org/download/)
|
93
93
|
- PostgreSQL Portable(10.1.1)
|
94
|
-
https://sourceforge.net/projects/postgresqlportable/files/v10.1.1/
|
94
|
+
[PostgreSQL Portable - Browse /v10.1.1 at SourceForge.net](https://sourceforge.net/projects/postgresqlportable/files/v10.1.1/)
|
95
95
|
- node.js(v14.3.0)
|
96
96
|
- Windows 10(64bit)
|
97
97
|
- Firefox(78.0.2)
|