• 로그인
  • 장바구니에 상품이 없습니다.

home2 게시판 Node.js, Express 게시판 axios에서 get요청을 보냈는데 server.js에서 받질 못합니다..

axios에서 get요청을 보냈는데 server.js에서 받질 못합니다..

7 글 보임 - 1 에서 7 까지 (총 7 중에서)
  • 글쓴이
  • #41132

    이무헌
    참가자
    App.js
    <button type='submit' onClick={()=>{axios.get('https://eccwithnodejs.df.r.appspot.com:443/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response)
    });}} >버튼</button>
    
    server.js
    
    app.get('https://eccwithnodejs.df.r.appspot.com:443/user',function(req,res){
    var tempUser={"name":"asd",
    "birth":970204,
    "email":"으헤헤헤이거슨이메일",
    "uid":"유니크다음은 전설"
    }
    res.send(tempUser);
    console.log(tempUser);
    })
    
     구글링을 해본 결과 https 프로토콜을 사용하기 위해선 ssl이 필요하고 openssl을 통해 다음과 같이 서버를 열었습니다.
    
    var server=http.createServer(app).listen(8080,function(){
        console.log('또 성공했구나..이녀석');
    })
    https.createServer(options,app).listen(443,function(){
        console.log('또 또 성공했구나..이녀석');
    })
    
    그럼에도 다음과 같은 오류가 뜨네요 ㅠ
    {data: '<!DOCTYPE html>\n<html lang="en">\n<head>\n<meta char…ody>\n
    Cannot GET /user

    \n</body>\n</html>\n', status: 404, statusText: '', headers: {…}, config: {…}, …}

    문제가 뭔지 알 수 있을까요? ㅠㅠㅠ

    #41198

    codingapple
    키 마스터
    서버에서 app.get('/user' 이렇게만 해놓으면 안될까요
    #41287

    이무헌
    참가자
    https로 통신하면 여전히404로 받질 못했습니다. ㅠㅠ 포트 8080 으로 http로 통신하니까 
    xhr.js:210          GET https://eccwithnodejs.df.r.appspot.com:8080/user net::ERR_CONNECTION_TIMED_OUT
    이렇게 오류가 뜨네요.. 서버쪽으로 요청은 간 것 같은데 AppEngine쪽에 문제가 있는 걸까요?
    아래는 선생님의 말씀에 따라 바꾼 코드입니다!
    
    App.js
    
    <button type='submit' onClick={()=>{axios.get('http://eccwithnodejs.df.r.appspot.com:8080/user').then((res)=>{console.log(res.data)}).catch(error => {
        console.log(error.response);
    });}} >버튼</button>
    
    
    
    server.js 
    
    
    app.get('/user',function(req,res){
    var tempUser={"name":"asd",
    "birth":970204,
    "email":"으헤헤헤이거슨이메일",
    "uid":"유니크다음은 전설"
    }
    res.send(tempUser);
    console.log(tempUser);
    })
     
    #41355

    codingapple
    키 마스터
    https 라이브러리 설치하고 셋팅하는 코드가 잘못된게 아닐까요 
    근데 app engine에 올리면 appspot.com어쩌구 기본 도메인은 인증서 설치같은거 자동으로 되어있어서 그냥 https로 요청잘될 수도 있습니다
    리액트에서 get요청시 뒤에 :8080은 없앱시다
    #41530

    이무헌
    참가자
    역시 https세팅이 잘 못 된거 같습니다 ㅠㅠㅠ https라이브러리 코드 수정해보겠습니다!! 감사합니다! ㅎㅎㅎ
    #41708

    이무헌
    참가자
    리액트서버 node js 서버 따로 여니까 잘 받아와 집니다!!! 휴 ㅠㅠ 토이프로젝트로 선생님들이 쓰시는 웹을 만들어야하는데 서버가 안 열려서
    식겁했네요 ㅜㅜ 감사합니다 선생님!! ssl은 구글에서 자동으로 발급해주고 역시 GAE가 문제였네요... 추가적인 질문인데 CORS는 어떻게 해결하는게
    가장 이상적인가요?? 지금은 일단  header("Access-Control-Allow-Origin", "*"); 로 허용 시켰는데 더 좋은 방법이 있을까요??
    #41768

    codingapple
    키 마스터
    nodejs react 합치기 어쩌구강의따라서 cors 라이브러리 설치하고 셋팅하는코드 추가합시다
7 글 보임 - 1 에서 7 까지 (총 7 중에서)
  • 답변은 로그인 후 가능합니다.

About

현재 월 700명 신규수강중입니다.

  (09:00~20:00) 빠른 상담은 카톡 플러스친구 코딩애플 (링크)
  admin@codingapple.com
  이용약관, 개인정보처리방침
ⓒ Codingapple, 강의 예제, 영상 복제 금지
top

© Codingapple, All rights reserved. 슈퍼로켓 에듀케이션 / 서울특별시 강동구 고덕로 19길 30 / 사업자등록번호 : 212-26-14752 온라인 교육학원업 / 통신판매업신고번호 : 제 2017-서울강동-0002 호 / 개인정보관리자 : 박종흠