Skip to content

Commit 598715c

Browse files
岸本靖之岸本靖之
岸本靖之
authored and
岸本靖之
committed
select文の更新
1 parent 150600b commit 598715c

File tree

3 files changed

+25
-36
lines changed

3 files changed

+25
-36
lines changed

memo/memo.txt

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
■起動手順
22
▼ローカル
33
アプリ起動
4+
cd /Users/Dmill/Dropbox/01_codes/text_node_express_mysql
45
nodemon [監視するディレクトリ]でサーバを起動し、npm install ~するときだけcontroll + cでサーバを停止
56
npm install ~したあとはnodemon [監視するディレクトリ]でサーバーを起動
67
→[Sun Oct 22 16:12:23]text_node_express_mysql Dmill$ nodemon text_node_express_mysql
@@ -9,7 +10,6 @@
910
MySQL起動(ローカル)
1011
$ mysql.server start
1112
▼サーバ
12-
AWSコンソールへのログイン
1313
AWSのマネジメントコンソールにログインする
1414
名前:各個人名
1515
パス:awsstudy@20170830
@@ -22,7 +22,7 @@
2222
事前に用意したAMIを選択し、作成ボタンを押下する
2323
画面にしたがって設定していく
2424
Nameタグ
25-
AWS_Workshop_02_test
25+
AWS_Workshop_02_氏名_main
2626
セキュリティグループ 名前はキーNameと一緒
2727
HTTP 80 0.0.0.0/0, ::/0
2828
SSH 22 マイIP
@@ -34,13 +34,13 @@
3434

3535
EC2_2台目の作成
3636
Nameタグ
37-
AWS_Workshop_02_test_sub
37+
AWS_Workshop_02_氏名_sub
3838
セキュリティグループ
3939
デフォルト(1台目と〃)
4040

4141
ELBの作成
4242
名前
43-
AWS-Workshop-02-test
43+
AWS-Workshop-02-氏名
4444
スキーマ
4545
インターネット向け
4646
IPアドレスタイプ
@@ -49,21 +49,21 @@
4949
VPCはデフォルトの
5050
AZは1a1c両方
5151
セキュリティグループ
52-
AWS-Workshop-02-test
52+
AWS-Workshop-02-氏名
5353
ターゲットグループ
5454
名前
55-
AWSWorkshop02Test
55+
AWSWorkshop02氏名
5656
ほかはそのまま
5757
2台のEC2を3000番で指定して「登録済み」押下
5858

5959
RDSセキュリティグループの作成
6060
EC2のセキュリティグループを確認する
6161
セキュリティグループ名(英語のやつ)をコピー
62-
AWS_Workshop_02_test
62+
AWS_Workshop_02_氏名
6363
新しいセキュリティグループを作成する
6464
・MySQL:EC2のセキュリティグループ←VPCをデフォルトのvpc-b523fなんちゃらに
6565
・Name、グループ名:AWS_Workshop_02_RDS
66-
これではないハズ→AWS_Workshop_02_test
66+
これではないハズ→AWS_Workshop_02_氏名
6767
・インバウンド
6868
MySQL TCP:3306 任意の場所をソースに
6969

@@ -131,6 +131,9 @@
131131
EC2 AWS_Workshop_02_#01
132132
GitHubからクローン
133133
[email protected]:kishimon/text_node_express_mysql.git
134+
gitから最新を取得
135+
git fetch origin master
136+
git reset --hard origin/master
134137

135138
db接続設定
136139
vi text_node_express_mysql/mysqlConnection.js
@@ -141,29 +144,35 @@
141144
DB
142145
bulletin_board
143146

144-
アプリ起動
147+
アプリ起動(ローカル)
148+
node /Users/Dmill/Dropbox/01_codes/text_node_express_mysql/bin/www
145149
cd text_node_express_mysql
146150
npm install -g -S moment
147151
npm install -g -S mysql
148152
node ./bin/www
153+
node text_node_express_mysql/bin/www
154+
画面アクセス(ローカル)
155+
http://localhost:3000
149156

150157
アプリ停止
151158
ps aux | grep node
152159
kill -9 <PROCESS_ID>
153160

154161
画面アクセス
155-
http://52.192.154.186:3000
156-
http://52.68.5.174:3000
162+
http://52.192.154.186:3000
163+
http://52.68.5.174:3000
157164

158165
EC2直で画面アクセス
159166
EC2_1のアプリ起動
160167
ssh -i .ssh/AWS_Workshop_02.pem [email protected]
168+
node text_node_express_mysql/bin/www
161169
cd text_node_express_mysql
162170
node ./bin/www
163171
EC2_2のアプリ起動
164172
ssh -i .ssh/AWS_Workshop_02.pem [email protected]
165173
cd text_node_express_mysql
166174
node ./bin/www
175+
node text_node_express_mysql/bin/www
167176
ELB経由で画面アクセス
168177
http://aws-workshop-02-test-55760466.ap-northeast-1.elb.amazonaws.com/
169178
express(不要?)
@@ -186,6 +195,7 @@
186195
ボードの見た目、もっと縦を詰めて行を増やす
187196
index.js
188197
EC2のIPを出力・MySQLに送ることで、ELBの証明
198+
→EC2のプライベートIPが出る、これをパブリックIPにしたほうがわかりやすいが
189199
■エラー
190200
Error: Can't set headers after they are sent.
191201
あるルートの中で一度レスポンスを返した場合に、別のレスポンスを返そうとした場合に発生するエラー

mysqlConnection.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
var mysql = require('mysql');
22

3-
// DB設定_ローカル
4-
// var dbConfig = {
5-
// host: '127.0.0.1',
6-
// user: 'root',
7-
// password: '',
8-
// database: 'bulletin_board'
9-
// };
10-
11-
// DB設定_本番
3+
// DB設定
124
var dbConfig = {
13-
host: 'awsworkshop02.cptxi3ftleus.ap-northeast-1.rds.amazonaws.com',
5+
host: 'XXXXXXXXXXXXXX.ap-northeast-1.rds.amazonaws.com',
146
user: 'awsworkshop02',
157
password: 'awsworkshop02',
168
database: 'bulletin_board'
179
};
1810

1911
var connection = mysql.createConnection(dbConfig);
2012

21-
module.exports = connection; // 外部からrequireできる形に
13+
module.exports = connection;

routes/index.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,9 @@ var moment = require('moment'); // moment.jsを読み込む
44
var os = require('os');
55
var connection = require('../mysqlConnection'); // Mysql接続
66

7-
/* GET home page. */
8-
// router.get('/', function(req, res, next) { // '/'はここではlocalhost:3000/(ルート直下)
9-
// // functionはここではコールバック関数
10-
// res.render('index', { title: 'Express' }); // render(viewファイル,←に渡すオブジェクト)
11-
// });
12-
137
router.get('/', function(req, res, next) {
14-
var query = 'SELECT * FROM boards';
8+
var query = 'SELECT * FROM boards ORDER BY board_id DESC LIMIT 20';
159
connection.query(query, function(err, rows) {
16-
console.log(rows);
1710
res.render('index', {
1811
title: 'testApp',
1912
boardList: rows
@@ -24,9 +17,6 @@ router.get('/', function(req, res, next) {
2417
router.post('/', function(req, res, next){
2518
var title = req.body.title; // フォームから送られたリクエストを受け取り、name属性titleを格納
2619
var createdAt = moment().format('YYYY-MM-DD HH:mm:ss'); // 現在時刻を格納
27-
console.log(os.networkInterfaces());
28-
// var serverIP = os.networkInterfaces().address.replace(".", "_"); // サーバIPを格納
29-
console.log(os.networkInterfaces().en0);
3020
var interfaces = os.networkInterfaces();
3121
var addresses = [];
3222
for (var k in interfaces) {
@@ -37,9 +27,6 @@ router.post('/', function(req, res, next){
3727
}
3828
}
3929
}
40-
console.log(addresses);
41-
42-
// MySQL
4330
var query = 'INSERT INTO boards (title, created_at) VALUES ("' + title + " from " + addresses + '", ' + '"' + createdAt + '")';
4431
connection.query(query, function(err, rows) {
4532
res.redirect('/');

0 commit comments

Comments
 (0)