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

home2 게시판 Node.js, Express 게시판 구글클라우드 배포if문안먹는상황

구글클라우드 배포if문안먹는상황

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

    박지오
    참가자
    강의보고 배포잘했습니다.
    근데 if문이 안먹네요. 
    간단하게 위치에따라 보여주냐안보여주냐인데 
    리액트에서도 잘되고 
    빌드해서 노드에서도 잘되는데 
    구글클라우드에 올리면 if문이 안먹네요 왜그럴까요 ㅠㅠ 
    
    <div className={styles.menuContainer}>
    {layout &&
    layout
     .slice(offset, offset + limit)
     .map(({ _id, title, category }, i) => {
    if (window.location == 'http://localhost:8080/menu') {
    return (
    <div className={styles.menuWrapper} key={i}>
    <Link to={`/menupopup/${_id}`}>
    <div className={styles.menuBox}>
    <p className={styles.menuItem}>{title}</p>{' '}
    <button
    className={styles.menuEditBtn}
    data-category={category}
    >
    <Link to={`/edit/${_id}`}>메뉴변경</Link>
    </button>
    </div>
    </Link>
    <button
    className={styles.menuDelBtn}
    data-id={_id}
    onClick={(e) => {
    deleteHandler(e);
    window.location.replace('/menu');
     }}
    >
     삭제
    </button>{' '}
    </div>
     );
     } else {
    return (
    <div className={styles.menuWrapper} key={i}>
    <Link to={`/menupopup/${_id}`}>
    <div className={styles.menuBox}>
    <p className={styles.menuItem}>{title}</p>
    </div>
    </Link>
    </div>
    
    #68681

    codingapple
    키 마스터
    localhost말고 실제주소로 바꾸거나 
    /menu가 포함되면~이라고 바꿉시다
    #68728

    박지오
    참가자
    잘해결했습니다. 감사합니다. 선생님 
    근데...에러가하나더있어서요.
    로컬에서는 추가 수정기능이 잘작동되는데 구글클라우드에 올리고
    수정하기 올리기 버튼을 누리면 
    internal server error
    이렇게 뜨네요. ㅠㅠ
    #68741

    codingapple
    키 마스터
    클라우드에서 서버 로그 출력해보거나 그 부분 코드를 확인해봅시다
    #68835

    박지오
    참가자
    코드입니다...!
    
    
    //추가코드
    app.post('/add/coffee', upload.single('image'), function (req, res) {
    res.send(
    "<script>location.href='https://original-nation-377813.du.r.appspot.com/menu';</script>"
     );
    //req.body라고 하면 요청했던 form에 적힌 데이터 수신가능
    console.log(req.body);
    console.log(req.body.background),
    db
     .collection('counter')
     .findOne({ name: '게시물갯수' }, function (err, result) {
    //resulte.totalPost = 총게시물갯수
    console.log(result.totalPost);
    //totalMenu = 총 게시물갯수
    const totalMenu = result.totalPost;
    //나중에 menu 음료 카테고리별로 분류
    db.collection('coffee').insertOne(
     {
    _id: totalMenu + 1,
    title: req.body.title,
    price: req.body.price,
    category: req.body.category,
    image: req.file.filename,
    background: req.body.background,
     },
    function (err, result) {
    console.log('저장완료');
    db.collection('counter').updateOne(
     { name: '게시물갯수' },
    //$set은 바꿀때사용
    //$inc는 기존값에 더해줄때사용 증가
     { $inc: { totalPost: 1 } },
    function (err, result) {
    if (err) {
    return console.log(err);
     }
     }
     );
     }
     );
     });
    });
    
    
    //수정코드
    app.put('/edit/coffee', upload.single('image'), function (req, res) {
    //updateOne은 하나만업데이트시킬때 사용 왼쪽 중괄호는 안에있는걸 찾아주세요.
    // 오른쪽 중괄호는 명령준대로 바꾸게된다.$set 업데이트해주세요,없으면 추가해주세요.라는뜻
    db.collection('coffee').updateOne(
    //body뒤의id 와title은 html안의 name이다.
     { _id: parseInt(req.body.id) },
    //https://codingapple.com/forums/topic/%EC%9D%B4%EB%AF%B8%EC%A7%80-%EC%97%85%EB%A1%9C%EB%93%9C-%EC%9D%91%EC%9A%A9-%EC%A7%88%EB%AC%B8%EB%93%9C%EB%A6%BD%EB%8B%88%EB%8B%A4/
    //이미지 해결
     {
    $set: {
    title: req.body.title,
    price: req.body.price,
    image: req.file.filename,
    background: req.body.background,
     },
     },
    function (err, result) {
    //완료알럿후 menupopup으로 돌아가기
    res.send(
    // alert('수정완료.');
    "<script>location.href='https://original-nation-377813.du.r.appspot.com/menu';</script>"
     );
    res.sendFile(__dirname + '/menu');
    console.log('수정완료');
    console.log(req.file.fieldname);
     }
     );
    });
    
    
    
    #68866

    codingapple
    키 마스터
    res.어쩌구를 연속2번하면 안됩니다 1개만 씁시다
6 글 보임 - 1 에서 6 까지 (총 6 중에서)
  • 답변은 로그인 후 가능합니다.

About

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

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

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