6 글 보임 - 1 에서 6 까지 (총 6 중에서)
-
글쓴이글
-
2023년 2월 16일 10:01 #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>
2023년 2월 17일 06:19 #68728
박지오참가자잘해결했습니다. 감사합니다. 선생님 근데...에러가하나더있어서요. 로컬에서는 추가 수정기능이 잘작동되는데 구글클라우드에 올리고 수정하기 올리기 버튼을 누리면 internal server error 이렇게 뜨네요. ㅠㅠ
2023년 2월 17일 17:31 #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); } ); });
-
글쓴이글
6 글 보임 - 1 에서 6 까지 (총 6 중에서)
- 답변은 로그인 후 가능합니다.