API 연결이 안됩니다.
298
작성한 질문수 58
.env 설정을 아래 3가지로 해 보고, 이것도 안되서 실제 아이피로 해 봤는데도 애뮬레이터 아래 undefined라는 오류 메시지만 뜨네요
; API_URL = http://192.168.0.255:3105
API_URL = http://10.0.2.2:3105
; API_URL = http://localhost:3105
SignUp.tsx 는 아래와 같이 되어 있습니다.
try {
setLoading(true);
const response = await axios.post(`${Config.API_URL}/user`, {
email,
name,
password,
});
console.log(response);
Alert.alert('알림', '회원가입이 완료되었습니다.');
} catch (error) {
const errorResponse = (error as AxiosError).response;
console.error(errorResponse);
if (errorResponse) {
Alert.alert('알림', errorResponse.data.message);
}
} finally {
setLoading(false);
}해당 패키지도 모두 설치하고, 서버도 재시작하고 했는데도 안되네요.
포트스맨으로 http://localhost:3105로 post 요청을 해 보면 아래와 같은 오류가 뜹니다.
TypeError: Cannot read properties of undefined (reading 'toLowerCase')
at /Users/xxx/React-Project/React-Native/back/app.js:104:27
at Layer.handle [as handle_request] (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/layer.js:95:5)
at /Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/index.js:341:12)
at next (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/index.js:275:10)
at urlencodedParser (/Users/xxx/React-Project/React-Native/back/node_modules/body-parser/lib/types/urlencoded.js:100:7)
at Layer.handle [as handle_request] (/Users/xxx/React-Project/React-Native/back/node_modules/express/lib/router/layer.js:95:5)
POST /user 500 7.179 ms - 2
답변 1
0
일단 백엔드은 실행되어있는 걸로 보입니다.
console.log(Config.API_URL) 해서 로깅되나 확인해보세요
0
try 문 바로 밑에
console.log('Config:::', Config.API_URL);
이렇게 넣었는데
안드로이드 기기에서는
LOG Ghh@ch.bd Fhhh fggg@#_322
LOG Config::: undefined
ERROR undefined이렇게 나오고 IOS 기기에서는
LOG Dfsdf@sdfsd.ffd Dsd tewt!@#123qwe
LOG Config::: http//localhost:3105
ERROR undefined이렇게 나옵니다.
API_URL 주소를 아래 3가지로 모두 해 봤는데 로그 내용은 동일합니다.
; API_URL = http://192.168.0.255:3105
; API_URL = http://10.0.2.2:3105
API_URL = http://localhost:3105
0
안드로이드에서는 메트로 서버를 껐다가 빌드를 다시 하시거나 react-native-config를 다시 설치하셔야할 것 같습니다.
ios에서는 되어야 정상입니다. ios 시뮬레이터 사파리에서 localhost:3105를 쳤을 때 들어가진다면요
0
매트로 서버를 그고 npm i react-native-config를 한 후에 다시 실행을 해 보니 3가지 API로 실행을 하면 모두 아래와 같이 나오네요..
안드로이드, 아이폰 모두 동일합니다.
LOG Fewer@wer.wer Werwer werwerwer!@#123
LOG Config::: undefined
ERROR undefined
0
Advanced Android Setup
In android/app/build.gradle, if you use applicationIdSuffix or applicationId that is different from the package name indicated in AndroidManifest.xml in <manifest package="..."> tag, for example, to support different build variants: Add this in android/app/build.gradle
defaultConfig {
...
resValue "string", "build_config_package", "ANDROIDMANIFEST_XML의_패키지_이름"
}
추가해보세요
build.gradle에도 다음 줄 있는지 봐보세요.
apply from: project(':react-native-config').projectDir.getPath() + "/dotenv.gradle"
0
가이드 해 주신대로 해봐도 안되서 이리저리 삽질하다가 결론은 프로젝트 모두 지우고 다시 처음부터 차근차근 다시 시도했습니다.
지금은 axios.post("http://localhost:3105/user'...로 요청을 하면 정상적으로 요청이 됩니다.
감사합니다.
앱실행시 네이버맵 [401] 에러
0
959
2
스타일링 라이브러리
0
147
2
expo, cli 선택 중에 고민이 있습니다.
0
167
2
JDK 버전이 달라도 괜찮나요?
0
223
2
dimenstion usewindowdeminstion
0
120
3
[맥 전용]환경 설정하기 1편 & [맥 전용]환경 설정하기 2편의 영상이 안나옵니다.
0
209
1
jdk11 버전과 gradle 버전의 호환성 관련 질문드립니다.
0
398
2
강의 외 질문입니다!
0
157
2
react native랑 맞는 ui 라이브러리 어떤게 좋을까요?
0
1487
2
react native와 spring boot 연결
0
353
1
java가 아닌 .kt에서 code push 에러가 발생합니다.
0
210
2
flipper 239 에러가 발생합니다.
0
163
2
package.json에 /lib/panino.js 문제입니다.
0
464
2
window - mac 협업 과정 질문합니다
0
214
1
ios 빌드 중 RCTBridgeDelegate.h import 오류
0
289
2
ios 앱 빌드 중 hermesEnabled 관련 오류발생
0
238
2
Socket 연결시 질문 드립니다.!
0
151
2
wifi 환경에서 axios 통신이 로컬서버에서 안됩니다.
0
425
2
iOS render error 질문드립니다.
0
410
2
iOS 가상머신 오류
0
164
2
npc react init 명령어 실행시 발생되는 오류
0
220
1
nom start 시 오류
0
116
1
NextJS 기반으로 만들어서 웹뷰 React Native로 배포 가능한가요?
0
996
2
안드로이드 rn75 버전에 맞게 설정 중에 android13 다운로드에 대해서 막혔습니다!
0
183
2





