teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ご回答をもとにコード修正するとエラー内容変更になったため追記。フロント部分のコードの修正も反映。

2021/01/01 11:19

投稿

webnakada
webnakada

スコア7

title CHANGED
File without changes
body CHANGED
@@ -12,9 +12,14 @@
12
12
  ```
13
13
 
14
14
  ```
15
-  ②
15
+  ②こちらのエラーはyu_1985さんのご回答より解決しました。ありがとうございました。
16
- xhr.js:177 GET http://localhost:9000/api/get net::ERR_CONNECTION_REFUSED
16
+ xhr.js:177 GET http://localhost:9000/api/get net::ERR_CONNECTION_REFUSED
17
17
  ```
18
+ ```
19
+  ③新しいエラー(2021/1/1追記)
20
+
21
+ net::ERR_CONNECTION_TIMED_OUT
22
+ ```
18
23
  #環境、コード
19
24
  ●サーバーOS: amazon linux2
20
25
 
@@ -23,22 +28,27 @@
23
28
 
24
29
  ```
25
30
  import React,{useState,useEffect} from 'react';
26
- import Axios from 'axios';
31
+ import AxiosBase from 'axios';
27
32
  import { Link } from 'react-router-dom';
28
33
  import { useForm } from 'react-hook-form';
29
34
  import TodoList from './todoList';
30
35
 
31
36
  const InputForm = () => {
37
+ const Axios = AxiosBase.create({
38
+ baseURL:"http://ec2-13-115-56-254.ap-northeast-1.compute.amazonaws.com:9000",
39
+ header:{'X-Requested-With': 'XMLHttpRequest'}
40
+ })
32
41
  const {register,handleSubmit,reset} = useForm();
33
42
  const [todoList,setTodoList] = useState([]);
34
- const [newTask,setNewTask] = useState([])
43
+ const [newTask,setNewTask] = useState([]);
35
44
 
45
+
36
46
  useEffect(() => {
37
- Axios.get('http://localhost:9000/api/get')
47
+ Axios.get('/api/get')
38
48
  .then((response) =>{
39
49
  setTodoList(response.data)
40
50
  })
41
- .catch((err) => console.log(err));   17行目 上記エラー発生箇所
51
+ .catch((err) => console.log(err));
42
52
  },[newTask.length])
43
53
 
44
54
  const onSubmit = async (data) => {
@@ -48,7 +58,7 @@
48
58
  task
49
59
  ]);
50
60
 
51
- Axios.post('http://localhost:9000/api/insert',{
61
+ Axios.post('/api/insert',{
52
62
  task:task,
53
63
  }).then((result) => console.log('成功'))
54
64
  .catch((err)=>console.log(err));
@@ -103,7 +113,7 @@
103
113
  const db = mysql.createPool({
104
114
  host:'ip-10-0-24-237.ap-northeast-1.compute.internal',
105
115
  user:'guestuser',
106
- password:'mfSndby1s#',
116
+ password:'**********',
107
117
  database:'todolist'
108
118
  })
109
119
 
@@ -139,7 +149,6 @@
139
149
  console.log(`port 9000`)
140
150
  });
141
151
 
142
-
143
152
  ```
144
153
 
145
154
 
@@ -153,4 +162,8 @@
153
162
  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
154
163
  mysqld 369 mysql 32u IPv6 57675 0t0 TCP *:33060 (LISTEN)
155
164
  mysqld 369 mysql 34u IPv6 57680 0t0 TCP *:3306 (LISTEN)
156
- ```
165
+ ```
166
+
167
+
168
+ ・自宅のネットワーク環境は問題なし
169
+ ・webサーバー間の通信も問題なし。pingにて確認。