묻고 답해요
156만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결[개정3판] Node.js 교과서 - 기본부터 프로젝트 실습까지
레디스 에러
redis는 4.6.10 버전 쓰고 있고 connect-redis는 7.1.0 버전을 쓰고 있습니다. 레디스 코드를 깃허브에 업데이트 된 것 처럼 수정해 주었는데 로그인을 하려니 C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\RESP2\encoder.js:17 throw new TypeError('Invalid argument type'); ^ TypeError: Invalid argument type at encodeCommand (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\RESP2\encoder.js:17:19) at RedisCommandsQueue.getCommandToSend (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\commands-queue.js:138:45) at Commander._RedisClient_tick (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:519:76) at Commander._RedisClient_sendCommand (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:506:82) at Commander._RedisClient_legacySendCommand (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:460:105) at Commander.sendCommand (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:432:114) at <computed> [as set] (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:478:27) at Object.set (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\connect-redis\dist\cjs\index.js:24:34) at RedisStore.set (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\connect-redis\dist\cjs\index.js:71:39) at Session.save (C:\Users\mikg2\Desktop\NodeBird-production\node_modules\express-session\session\session.js:72:25) Emitted 'error' event on Commander instance at: at C:\Users\mikg2\Desktop\NodeBird-production\node_modules\@redis\client\dist\lib\client\index.js:466:31 Node.js v18.16.0이런 에러가 뜨는데 버전 문제인가요? 모듈 내부적으로 발생한 거라 어디를 손봐야 할 지 모르겠습니다.참고로 세션 객체는Session { cookie: { path: '/', _expires: null, originalMaxAge: null, httpOnly: true, secure: false } }이렇게 찍혔습니다.
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
mySql DB 는 생성하였는데 테이블이 생성이 안되는 경우가 어떤 게 있을 까요?
윈도우로 하려니 참 수업이 쫒아가기 힘드네요.어찌 어찌 구글링으로 계속 진행하고 있는데요.도커로 올린 후 DB 는 생성을 했는데 테이블 생성이 안되네요. 2. localhost:4000 로 접속을 하면 화면이 보이지도 않구요. 아..도커 참 그렇네요. ^^: 이것 저것 손 댄 코드 입니다. 14 버전이 안되어서 16버전으로 변경# 컴퓨터 만드는 설명서 # 1. 운영체제 설치(node 14버전과 npm과 yarn이 모두 설치되어있는 리눅스) FROM node:16 # 2. 내 컴퓨터에 있는 폴더나 파일을 도커 컴퓨터 안으로 복사하기 COPY ./package.json /myfolder/ COPY ./yarn.lock /myfolder/ WORKDIR /myfolder/ RUN yarn install COPY . /myfolder/ # 3. 도커안에서 index.js 실행시키기 CMD yarn start:dev DB 포트 충돌로 3307번 확인 후 3306 번 접근version: '3.7' services: my-backend: build: context: . dockerfile: Dockerfile volumes: - ./src:/myfolder/src ports: - 4000:3000 env_file: - ./.env.docker my-database: platform: linux/x86_64 image: mysql:latest environment: MYSQL_DATABASE: 'mydocker' MYSQL_ROOT_PASSWORD: '0000' ports: - 3307:3306 도움 좀 부탁드립니다.
-
해결됨Slack 클론 코딩[백엔드 with NestJS + TypeORM]
socket.io 사용시 랜덤하게 객체가 emit 됩니다.
안녕하세요 제로초님~ 백엔드 개발자 지망생이자 제로초님의 팬인 신유빈입니다.1개월 가량 하기 문제를 구글링 하며 여러 경우의 수를 찾아보았지만 이유를 찾지 못하여 질문드립니다.질문드리고자 하는 내용은 이렇습니다.socket.io 로 이벤트를 emit 할때, 같은 메서드를 사용함에도 객체에 따라 클라이언트에 전송될 때도 있고, 전송되지 않을 때도 있는데 그 원인을 찾지 못하고 있습니다.현재 저는 신규게시물 혹은 댓글이 작성되었을때 모든 사용자에게 알림을 emit 하고자 합니다.현재 3가지의 경우 중 A만 성공중인 상태입니다.A : 테스트를 위하여 handleConnection 메서드에서 소켓에 연결한 사용자의 정보 객체를 message 로 전송시 성공B : 게시물 작성 시 생성한 알림 메시지 객체를 message 로 전송시 실패C: 댓글 작성 시 생성한 알림 메시지 객체를 message 로 전송시 실패모든 케이스에서 클라이언트에게 메시지를 성공적으로 보내려면 어떻게 해야할지 도움을 주실 수 있을까요?// 실행 동영상 https://youtu.be/AgLmcV53EvM// 코드깃허브 저장소 전체 코드https://github.com/fog-of-war/dev-be/blob/zerocho/README.mdEventsGatewayhttps://github.com/fog-of-war/dev-be/blob/zerocho/src/events/events.gateway.ts#L55 // fow-be/src/events/events.gateway.ts /** 웹소켓 연결시 */ handleConnection(@ConnectedSocket() socket: Socket, client: any) { const interval = setInterval(() => { const userInfo = socket.userInfo; this.sendMessage(userInfo); }, 5000); socket.on("disconnect", () => { clearInterval(interval); }); } /** 메시지 전송 */ sendMessage(message?: any) { console.log(" \n 🌠 sendMessage \n", message); this.server.emit("message", message); return Promise.resolve("Message sent successfully"); } AlertServicehttps://github.com/fog-of-war/dev-be/blob/zerocho/src/alert/alert.service.ts#L12 // fow-be/src/alert/alert.service.ts // B: 게시물 작성시 실행되는 알림 서비스 코드 async createNotifyAlert(id: number) { const data = { alert_place_id: id, alert_type: "NOTIFY" as Type }; const alert = await this.prisma.alert.create({ data: data }); const result = await this.makePostAlertMessage(id); await this.eventsGateway .sendMessage(result) .then((response) => { // console.log("🌠 Notification sent successfully:", response); }) .catch((error) => { console.error("🌠 Error sending notification:", error); // 전송 실패 또는 오류가 발생한 경우에 실행할 로직을 여기에 추가 }); return result; }// fow-be/src/alert/alert.service.ts // C : 댓글 작성시 실행되는 알림 서비스 코드 async createActivityAlert(id: number) { const data = { alert_comment_id: id, alert_type: "ACTIVITY" as Type }; const alert = await this.prisma.alert.create({ data: data }); const result = await this.makeCommentAlertMessage(id); await this.eventsGateway .sendMessage(result) .then((response) => { // console.log("🌠 Notification sent successfully:", response); }) .catch((error) => { console.error("🌠 Error sending notification:", error); }); return result; } // 출력결과# A : 클라이언트에 전송 성공 🌠 sendMessage { sub: 2, user_email: 'shin.yubin18@gmail.com', iat: 1695983169, exp: 1695986769 } # B : 클라이언트에 전송 실패 🌠 sendMessage { place_id: 1, place_name: '코엑스', region_name: '강남구', post_id: 65, post_created_at: 2023-09-29T10:27:28.371Z, post_image_url: 'https://fog-of-war.s3.ap-northeast-2.amazonaws.com/랜드마크/1코엑스.jpeg' } # C : 클라이언트에 전송 실패 🌠 sendMessage { user_nickname: '구글신유빈', user_image_url: 'https://fog-of-war.s3.ap-northeast-2.amazonaws.com/defaultProfile.png', comment_id: 15, comment_text: '우왕', comment_created_at: 2023-09-29T10:52:24.960Z }
-
미해결비전공자를 위한 진짜 입문 올인원 개발 부트캠프
저도 가로 배치가 잘되다가 세로 배치가 되어 질문드립니다.
저도 강의 따라가다가 세로로 갑자기 변환되어서 답변 내용대로 해봤지만 고쳐지지를 않아서 질의 드립니다 아래 코드는 html코드입니다<html> <head> <title>그랩마켓</title> <link href="index.css" type="text/css" rel="stylesheet" /> <body> <div id="header"> <div id="header-area"> <img src="images/images/icons/logo.png"/> </div> </div> <div id="body"> <div id="banner"> <img src="images/images/banners/banner1.png"/> </div> <h1>판매되는 상품들</h1> <div id="product-list"> <div class="product-card"> <img class="product-img" src="images/images/products/basketball1.jpeg"/> <div class="product-contents"> <span class="product-name">농구공 1호</span> <span class="product-price">50000원</span> <div class="product-seller"> <img class="product-avatar" src="images/images/icons/avatar.png"/> <span>그랩</span> </div> </div> </div> </div> <div class="product-card"> <img class="product-img" src="images/images/products/keyboard1.jpg"/> <div class="product-contents"> <span class="product-name">키보드 1호</span> <span class="product-price">30000원</span> <div class="product-seller"> <img class="product-avatar" src="images/images/icons/avatar.png"/> <span>그랩</span> </div> </div> </div> <div class="product-card"></div> <div class="product-card"></div> </div> <div id="footer"></div> </body> </head> </html>아래는 css코드입니다 * { margin: 0; padding: 0; } #header{ height: 64px; display: flex; justify-content: center; border-bottom: 1px solid gray; } #body{ min-height: 100%; width: 1024px; margin: 0 auto; padding-bottom: 24px; } #footer{ height: 200px; background-color: red; } #banner{ height: 300px; background-color: yellow; } #header-area{ width: 1024px; height: 100%; display: flex; align-items: center; } #header-area > img{ width: 128px; height: 36px; } #body > h1{ margin-top: 16px; } #banner > img{ width: 100%; height: 300px; } #product-list{ display: flex; flex-wrap: wrap; margin-top: 12px; flex-direction: row; } .product-card{ width: 180px; height: 300px; margin-right: 12px; margin-bottom:12px; border: 1px solid rgb(230, 230, 230); border-radius: 12px; } .product-img{ width: 100%; height: 210px; } .product-contents{ display: flex; flex-direction: column; padding: 8px; } .product-name{ font-size: 14px; } .product-price{ font-size: 16px; font-weight: 200px; margin-top: 4px; } .product-seller{ display: flex; align-items: center; margin-top: 12px; } .product-avatar{ width: 24px; }바쁘시겠지만 답변 해주시면 감사하겠습니다!+해당 코드 진행 후 개발자 도구 이용해서 보면 flex에 의해 정해지지않은 보라색 칸이 있는데 해당 칸 처리가 힘들어 추가 질문 올립니다!
-
미해결이미지 관리 풀스택(feat. Node.js, React, MongoDB, AWS)
axios 이용해서 백엔드로 이미지 전송 중 새로고침
안녕하세요 강사님.현재 axios 이용해서 백엔드로 이미지 전송하기 강의 수강 중npm i axios로 Axios 모듈 설치 후다음과 같이 코드 작성, npm run start 후 제출 버튼 누를 때 계속하여 새로고침이 됩니다.. ㅠ 원래라면 preventDefault로 새로고침이 되지 않아야 할텐데계속해서 새로고침이 되는 문제입니다. 혹시 문제가 뭘까요? ㅠ
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
res.on('finish')
안녕하세요 강의 잘 듣고 있습니다.res.on('finish', cb); 이벤트를 걸어뒀다고 가정하고 만약 어떤 request에 의한 비즈니스 로직 수행 중적당한 예외처리가 되지 못해서 서버가 죽어버리는 로직을 거쳐 res를 쏘는 부분까지 도달하지 못했다면해당 cb함수는 실행되지 않을거라고 생각했는데 맞을까요?(이렇게 되면.. 어떤 요청에 의해 프로그램이 죽었는지 알기 어려울 것 같다는 생각이 문득 들어서 질문드립니다)
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
redis 질문있습니다.
redis를 도커로 설치하는 이유가 따로 있을까요?
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
brew 명령어를 찾을수 없음
몽고 DB root설정하는 부분에서 이런 오류가 나는데 어떻게 해결해야할까요?
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
섹션2-8 openWeatherMap API
const weatherSearch = function (position) { const openWeatherRes = fetch( `https://api.openweathermap.org/data/2.5/onecall?lat=${position.latitude}&lon=${position.longitude}&appid=4bdfd4f45f4d597908e29058919e8707` ); console.log(openWeatherRes); }; const accessToGeo = function (position) { const positionObj = { latitude: position.coords.latitude, longitude: position.coords.longitude, }; weatherSearch(positionObj); }; const askForLocation = function () { navigator.geolocation.getCurrentPosition(accessToGeo, (err) => { console.log(err); }); }; askForLocation(); fetch 안에 2.5로 변경해도 계속 오류가 떠요 ㅠ어떻게 해야하나요?
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
고양이 정보 커뮤니티 프론트앤드와 합칠 때 오류
일단 먼저 제 상황을 말씀드릴게요 섹션 4에 강의 협업을 위한 API만들기와 CORS 문제 강의를 듣던중 프론트앤드 파일을 다운받아서 프론트앤드 파일을 열고 회원가입을 해보는 부분에서 프론트 앤드 파일이 열리지 않았습니다.강의가 작성 된지 시간이 오래 된 것인지 아니면 제가 아직 고양이 정보 커뮤니티에 대한 강의를 다 듣지 못해서 인지 확신이 되지 않아 강사님의 깃허브 05 실전 프로젝트 파일을 다운받아 npm i 로 전부 설치했고(이 때도 워낙 버전이 달라서 버전 fix 를 하는 과정이 필요했습니다.) 그리고 프론트 부분의 파일도 받아서 cd로 프론트파일쪽 폴더로 접근한다음 npm i 로 프론트에 해당하는 패키지까지 전부 설치했습니다. ( 프론트쪽 버전은 백보다 더욱 심각해서 npm install react@latest react-dom@latest 이 명령어를 쳐서 버전업을 하지 않으면 아에 오류가 뜨는 정도였습니다..) 어쨋든 이러한 과정을 마치고 localhost:3000/signup 을 실행하면 이런식으로 오류가 생기면서 되질않았습니다. 이건 일부분의 오류이고 훨씬 더 많은 오류가 생겼습니다.하나하나 다 열거하기 힘들정도라서 개인적으로 이 코드들을 수정하는것이 제 수준에선 불가능했습니다.질문에 답변하신 것을 보니 2023년에도 호환성에 문제가 없다고 되어있는데 진짜 그런지 잘모르겠습니다.
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
비주얼 스튜디오 코드 폴더명 변경시 오류
section03 의 03-10 폴더를section04 에 복사 후이름을 변경하면error:EPERM: OPERATION NOT PERMITTED 가떠서, 비주얼스튜디오코드를 종료후 다시 시작해야 변경이 되는데, 복사 붙이기로 붙여넣은 후에는 별다른 작업을 하지 않았는데도, 왜 이런 오류가 발생되는 걸까요? node_modules를 제외하고 복사 후 npm i 로 설치해야 하나요? 매번 계속 시작하려니 시간이 많이 낭비되는듯하여질문 드립니다~답변주시면 감사하겠습니다~
-
해결됨[리뉴얼] React로 NodeBird SNS 만들기
안녕하세요, 리덕스를 통해서 좋아요 기능구현을 해보고 있는데 디스패치와 충돌이 나는것 같습니다.
안녕하세요, 좋은 강의 감사드립니다. 제가 좋아요 기능구현을 해보고 있는데, 클릭이 되면 state(clicked)를 통해 true로 만들어서 빨강색으로 만들고 1를 추가시키고 다시 클릭하면 false가 되면서 검게 되고 1을 감소하게 하는 기능을 구현하려고 하는데요. 각각 빨/검 1추가시키기는 되는데 둘이 합치려니까 1을 올리면서 리렌더링이 되고 clicked라는 스테이트가 바로 false로 초기화되버리는것 같습니다. 혹시 방법이있을까요? 뭐라고 검색해야 할지 감이 잘안잡혀서 질문남깁니다. const Heart = ({ pageId, id, currentIndex, postId, }) => { const dispatch = useDispatch(); const { coursePosts } = useSelector((state) => state.coursePost); const { clicked, setClicked } = useState(false); const heart = coursePosts[currentIndex].CourseReview[id].heart; const onClickHeart = () => { if (!clicked) { dispatch(coursePostActions.clickCourseReviewHeart({ pageId, postId })) } else { dispatch(coursePostActions.clickCourseReviewHeartAgain({ pageId, postId })) } setClicked(!clicked); } return ( <button type="button" onClick={onClickHeart} className={clicked === true ? styles.active : ""}> <FontAwesomeIcon icon={faHeart} /> <span>{heart}</span> </button> ); }; export default CourseReviewItems;const coursePostSlice = createSlice({ name: "coursePost", initialState, reducers: { clickCourseReviewHeart(state, action) { const postIndex = state.coursePosts.findIndex((v) => v.id === Number(action.payload.pageId)); const reviewIndex = state.coursePosts.findIndex((v) => v.id === action.payload.postId); state.coursePosts[postIndex].CourseReview[reviewIndex].heart += 1 }, clickCourseReviewHeartAgain(state, action) { const postIndex = state.coursePosts.findIndex((v) => v.id === Number(action.payload.pageId)); const reviewIndex = state.coursePosts.findIndex((v) => v.id === action.payload.postId); state.coursePosts[postIndex].CourseReview[reviewIndex].heart -= 1 } }
-
미해결[리뉴얼] React로 NodeBird SNS 만들기
강좌 끝나고 댓글 수정 기능 만들어 보고 있습니다
{commentFormOpened && ( <div> {commentEditMode ? <CommentContent post={post} commentEditMode={commentEditMode} onClickUpdateComment={onClickUpdateComment} onCancelUpdateComment={onCancelUpdateComment} /> : ( <> <CommentForm post={post} /> <CommentContent post={post} commentEditMode={commentEditMode} onClickUpdateComment={onClickUpdateComment} onCancelUpdateComment={onCancelUpdateComment} /> </> ) } </div> )} //PostCard.js import React, { useCallback, useEffect, useState } from 'react'; import { Avatar, Comment, List, Input, Button, Popover } from 'antd'; import { useDispatch, useSelector } from 'react-redux'; import Link from 'next/link'; import PropTypes from 'prop-types'; import { EllipsisOutlined } from '@ant-design/icons'; import { UPDATE_COMMENT_REQUEST } from '../reducers/post'; const {TextArea} = Input; const CommentContent = ({ post, onCancelUpdateComment, commentEditMode, onClickUpdateComment }) => { const dispatch = useDispatch(); const id = useSelector((state) => state.user?.me.id); const { updateCommentLoading, updateCommentDone } = useSelector((state) => state.post); const [editText, setEditText] = useState(post.Comments.content); useEffect(() => { if (updateCommentDone) { onCancelUpdateComment(); } }, [updateCommentDone]); const onChangeCommentText = useCallback((e) => { setEditText(e.target.value); }, []); const onChangeComment = useCallback(() => { dispatch({ type: UPDATE_COMMENT_REQUEST, data: { PostId: post.id, CommentId: post.Comments.id, UserId: id, content: editText, }, }); }, [post, id, editText, post.Comments.id]); return ( <div> {commentEditMode ? ( <> <TextArea value={editText} onChange={onChangeCommentText} /> <Button.Group> <Button loading={updateCommentLoading} onClick={onChangeComment}>수정</Button> <Button type="danger" onClick={onCancelUpdateComment}>수정 취소</Button> </Button.Group> </> ) : <List header={`${post.Comments.length}개의 댓글`} itemLayout="horizontal" dataSource={post.Comments} renderItem={(item) => ( <li> <Comment actions={[<Popover key="more" content={ <Button.Group> {id && item.User.id === id ? ( <> <Button onClick={onClickUpdateComment}>수정</Button> <Button type="danger"> 삭제 </Button> </> ) : ( <Button>신고</Button> )} </Button.Group> } > <EllipsisOutlined /> </Popover>,]} author={item.User.nickname} avatar={ <Link href={`/user/${item.User.id}`}> <a><Avatar>{item.User.nickname[0]}</Avatar></a> </Link> } content={item.content} /> </li> )} /> } </div> ) } CommentContent.propTypes = { post: PropTypes.shape({ id: PropTypes.number.isRequired, Comments: PropTypes.arrayOf(PropTypes.shape({ id: PropTypes.number.isRequired, content: PropTypes.string.isRequired, })) }), onCancelUpdateComment: PropTypes.func.isRequired, onClickUpdateComment: PropTypes.func.isRequired, commentEditMode: PropTypes.bool }; CommentContent.defaultsProps = { commentEditMode: false, } export default CommentContent; //CommentContent.js case UPDATE_COMMENT_REQUEST: draft.updateCommentLoading = true; draft.updateCommentDone = false; draft.updateCommentError = null; break; case UPDATE_COMMENT_SUCCESS: draft.updateCommentLoading = false; draft.updateCommentDone = true; const post = draft.mainPosts.find((v) => v.id === action.data.PostId); post.Comments = post.Comments.find((v) => v.id === action.data.CommentId); post.Comments = post.Comments.find((v) => v.id === action.data.UserId); post.Comments.content = action.data.content; break; case UPDATE_COMMENT_FAILURE: draft.updateCommentLoading = false; draft.updateCommentError = action.error; break; //reducers/post.js function updateCommentAPI(data) { return axios.patch(`/post/${data.PostId}/comment`, data); } function* updateComment(action) { try { const result = yield call(updateCommentAPI, action.data); yield put({ type: UPDATE_COMMENT_SUCCESS, data: result.data, }); } catch (err) { console.error(err); yield put({ type: UPDATE_COMMENT_FAILURE, error: err.response.data, }); } } // sagas/post.js router.patch('/:postId/comment', isLoggedIn, async (req, res, next) => { // PATCH post/2/comment try { await Comment.update({ content: req.body.content, }, { where: { PostId: req.params.postId, UserId: req.user.id, }, }); res.status(200).json({ PostId: parseInt(req.params.postId, 10), UserId: req.user.id, content: req.body.content, }); } catch (error) { console.error(error); next(error); } }); //routes/post.js이렇게 PostId, UserId, content가 보내지고, 실패가 뜨면서 새로고침을 하면 해당 글에 달았던 댓글들이 모두 다 "zzz"로 변경되어 있습니다. 그래서 CommentId를 보내줘야 될 거 같은데 여기서 막혀서 감이 도무지 잡히질 않습니다.
-
미해결이미지 관리 풀스택(feat. Node.js, React, MongoDB, AWS)
ImageList 컴포넌트에서 업로드 한 사진을 리스트에서 바로 보기 위해 이 방법도 괜찮나요??
ImageList 컴포넌트 안에 있는 useEffect 종속배열 안에 images를 넣게 되면 images가 변경될 때마다 get을 호출해서 사진을 불러오기 때문에 결과적으로 사진을 업로드하면 리스트에 바로 보여지긴 하는데 안 좋은 방법인가요? 선생님께서 ContextAPI를 사용해 관리하는 것과 제가 생각한 방법의 장단점이 궁금해요 const [images, setImages] = useState([]); useEffect(() => { axios .get("/images") .then((res) => setImages(res.data)) .catch((err) => console.log(err)); }, [images]); // images 추가!
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
중소,스타트업에서는 코딩테스트 안 보는 곳도 있나요?
중소, 스트타업 채용공고 찾아봤는데 코딩테스트를 보는 곳도 있고 아닌 곳도 있는 거 같아서 무조건 보는 건 아닌가요?
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
section23. 04-06 Mongoose 활용편 질문입니다.
안녕하세요.MongoDB compass로 mongodb://localhost:27017로 접속시, 네임레졸루션으로 설정한 mydocker가 데이터베이스가 보이지 않습니다.어떻게 하면 MongoDB compass에서 mydocker를 볼 수 있게 할 수 있는지 알려주시면 감사하겠습니다. <네임레졸루션으로 설정한 mydocker>mongoose .connect("mongodb://my-database:27017/mydocker") .then(() => console.log("Connected!")) .catch(() => console.log("Connection Failed")); app.listen(4000, () => { console.log("Back-end API is Open Now"); }); CLI로 MongoDB id "ce236b58a149"로 접속하여 확인하여 보면 mydocker가 확이, Postman으로 확인하여도 POST GET가 잘 됩니다만, MongoDB compass로 접속이 되지 않습니다.<CLI로 mydocker 데이터베이스 확인>hyunminyu@HYUNMINnoAir class % docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ce236b58a149 mongo:5 "docker-entrypoint.s…" 12 seconds ago Up 11 seconds 0.0.0.0:27017->27017/tcp backend-my-database-1 e3f0f648c4c3 backend-my-backend "docker-entrypoint.s…" 21 minutes ago Up 11 seconds 0.0.0.0:4000->4000/tcp backend-my-backend-1 hyunminyu@HYUNMINnoAir class % docker exec -it ce236b58a149 /bin/bash root@ce236b58a149:/# mongo MongoDB shell version v5.0.21 connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb Implicit session: session { "id" : UUID("181ced5f-7b45-4fd5-bb08-c90762778e68") } MongoDB server version: 5.0.21 ================ Warning: the "mongo" shell has been superseded by "mongosh", which delivers improved usability and compatibility.The "mongo" shell has been deprecated and will be removed in an upcoming release. For installation instructions, see https://docs.mongodb.com/mongodb-shell/install/ ================ --- The server generated these startup warnings when booting: 2023-09-22T15:44:38.346+00:00: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem 2023-09-22T15:44:39.191+00:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted --- > show databases admin 0.000GB config 0.000GB local 0.000GB mydocker 0.000GB > use mydocker switched to db mydocker > show collections boards한가지 의심스러운 점이 있습니다.docker-compose.yaml에서 아래의 27017:27017 포트포워딩을 주석처리하여 docker up을해도, MongoDB compass로 mongodb://localhost:27017로 접속이 되는점이 혹시 문제 원인과 관련이 있지 않을까 생각이 듭니다. ports: - 27017:27017 감사합니다.
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
강의10-8 관련 질문입니다.
products.service.ts// 2-2) 상품태그 등록 const tagNames = productTags.map((el) => el.replace('#', '')); const prevTags = await this.productsTagsService.findByNames({ tagNames }); const temp = []; tagNames.forEach((el) => { const isExists = prevTags.find((prevEl) => el === prevEl.name); if (!isExists) temp.push({ name: el }); }); const newTags = await this.productsTagsService.bulkInsert({ names: temp }); const tags = [...prevTags, ...newTags.identifiers]; productsTags.service.tsconst newTags = await this.productsTagsService.bulkInsert({ names: temp }); const tags = [...prevTags, ...newTags.identifiers]; products.service.ts 에서const tags = [...prevTags, ...newTags.identifiers];의 결과로 주석으로 {id: "전자제품ID", {id: "컴퓨터ID}, {id: "영등포ID"}}이렇게 적어주셨는데 ...newTags.identifiers는 결과가 저렇게 id로 들어가는게 이해되는데 ...prevTags는 왜 id로 들어가는지 이해가 잘 안됩니다..prevTags는 키가 id랑 name 두개 있는 객체인데 왜 저렇게 들어가는걸까요 ?? spread 연산자를 사용해서일까요 주석의 예시대로라면{id: "전자제품ID", name: "전자제품"}, {id: "컴퓨터ID"}, {id: "영등포ID"}}이런식으로 들어가야 하는거 아닌가요??감사합니다
-
미해결Slack 클론 코딩[백엔드 with NestJS + TypeORM]
socketio 질문 있습니다.
안녕하세요. 마이크로 서비스를 만들어 보고있습니다. 서버끼리는 gRPC 통신을 사용하고, 클라이언트는 게이트웨이를 통해서 HTTP통신을 하는 형태로 만들고있습니다.요구사항은 이제 어느정도 다 구현이 된 상태인데요. 데이터베이스의 데이터를 모두 보여주는 화면에서 새로운 데이터가 입력됐을때 실시간으로 보여주기 위해서 웹 소켓을 사용하려고 합니다.그래서 게이트웨이에 웹소켓 게이트웨이를 추가했습니다. import { Inject, OnModuleInit } from '@nestjs/common'; import { MessageBody, SubscribeMessage, WebSocketGateway, WebSocketServer, } from '@nestjs/websockets'; import { Server } from 'socket.io'; import { CounselServiceClient } from './../../../proto/src/counsel'; import { ClientGrpc } from '@nestjs/microservices'; import { firstValueFrom } from 'rxjs'; @WebSocketGateway({ cors: { origin: '*' } }) export class EventsGateWay implements OnModuleInit { counselService: CounselServiceClient; constructor(@Inject('COUNSEL_PACKAGE') private clientCounsel: ClientGrpc) {} onModuleInit() { this.counselService = this.clientCounsel.getService<CounselServiceClient>('CounselService'); } @WebSocketServer() server: Server; @SubscribeMessage('getAllCounselAdmin') async getAllCounselAdmin() { const result = await firstValueFrom( this.counselService.getAllCounselAdmin({}) ); this.server.emit('allCounselAdminData', result); } @SubscribeMessage('getCounselAdmin') async getCounselAdmin(@MessageBody() data: any) { const counselId = data.counselId; const result = await firstValueFrom( this.counselService.getCounselAdmin({ counselId }) ); this.server.emit('counselData', result); } }이게 지금 웹소켓 게이트웨이의 코드입니다. 클라이언트와 연결하기 위해서'use client'; import { useEffect, useState } from 'react'; import { CounselProto } from './../../../proto/src/counsel'; import axios from 'axios'; import Long from 'long'; import Link from 'next/link'; import { io } from 'socket.io-client'; export const statusInfoMap: { [key: number]: string } = { 1: '', 2: '', 3: '', 4: '', 5: '', }; export default function GetAllCounselByAdmin() { const [counselData, setCounselData] = useState<CounselProto[]>([]); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const socket = io('http://localhost:3000'); socket.on('connect', () => { console.log('Connected to the server'); }); socket.on('allCounselAdminData', (data) => { console.log('Received data: ', data); setCounselData(data); }); socket.on('disconnect', () => { console.log('Disconnected from the server'); }); return () => { socket.disconnect(); }; }, []); return ( <div> {isLoading ? ( <p>Loading...</p> ) : ( <> <h1>모든 상담 내역 조회</h1> <table> <thead> <tr> <th>[상담 기록 번호]</th> <th>[상담 접수 내용]</th> <th>[상담 진행 상황]</th> <th>[상담 접수 날짜]</th> <th>[고객 고유 번호]</th> <th>[고객 성함]</th> <th>[고객 연락처]</th> </tr> </thead> <tbody> {counselData?.map((item, i) => ( <tr key={i}> <td> <Link href={`/admin/counsel/${item.counselId}`}> {item.counselId} </Link> </td> <td>{item.content}</td> <td>{statusInfoMap[item.statusInfo]}</td> <td>{item.createdAt.toLocaleString()}</td> <td>{item.counselUserId}</td> <td>{item.name}</td> <td>{item.phone}</td> </tr> ))} </tbody> </table> </> )} </div> ); }이렇게 적고 서버를 실행해서 해당 페이지에 접속을 하니까 콘솔에 Connected to the server라고는 뜨는데, 데이터가 꽂히지 않고있습니다.서버로 부터 데이터를 못 받아오고있는것같은데요. 어떤 부분을 손대야할지 모르겠습니다. 해당 소켓 게이트웨이는 공식문서를 참고해서 적었습니다..
-
해결됨[리뉴얼] React로 NodeBird SNS 만들기
툴킷에서 SSR적용하는 부분 질문있습니다.
강의 들은 부분을 툴킷으로 다시 만들어보는중 SSR 적용하는 부분 질문있습니다. 초기 로딩후 로그인은 정상적으로 동작하는데요 새로고침하고 로그인 풀린 화면이 나오고 다시 로그인하면 로그인되지 않습니다. 코드는 다음과 같이 작성했습니다. // toolkit/index.ts import axios from 'axios'; import userSlice, { UserInitialState } from './user'; import postSlice, { PostState } from './post'; import { AnyAction, CombinedState } from '@reduxjs/toolkit'; import { combineReducers } from 'redux'; import { HYDRATE } from 'next-redux-wrapper'; axios.defaults.baseURL = 'http://localhost:3065'; axios.defaults.withCredentials = true; export interface IState { user: UserInitialState; post: PostState; } const rootReducer = ( state: IState, action: AnyAction ): CombinedState<IState> => { switch (action.type) { case HYDRATE: return action.payload; default: { const combinedReducer = combineReducers({ user: userSlice.reducer, post: postSlice.reducer, }); return combinedReducer(state, action); } } }; export default rootReducer;툴킷에 HYDRATE를 적용하고 // store/configureStore.ts import { AnyAction, Reducer, configureStore } from '@reduxjs/toolkit'; import { createWrapper } from 'next-redux-wrapper'; import rootReducer, { IState } from '../toolkit'; const makeStore = () => configureStore({ reducer: rootReducer as Reducer<IState, AnyAction>, devTools: true, middleware: (getDefaultMiddleware) => getDefaultMiddleware(), }); export default createWrapper<AppStore>(makeStore, { debug: process.env.NODE_ENV !== 'production', }); export type AppStore = ReturnType<typeof makeStore>; export type RootState = ReturnType<typeof rootReducer>; export type AppDispatch = AppStore['dispatch']; 리덕스 래퍼 부분은 저렇게 만들고 //pages/index.tsx export const getServerSideProps: GetServerSideProps = wrapper.getServerSideProps((store) => async ({ req }) => { const cookie = req ? req.headers.cookie : ''; axios.defaults.headers.Cookie = ''; if (req && cookie) { axios.defaults.headers.Cookie = cookie; } await store.dispatch(loadPostAction()); await store.dispatch(loadUserAction()); }); export default Home; // toolkit/user.ts export const loadUserAction = createAsyncThunk( 'user/loadUser', async (data) => { const response = await axios.get(`/user/${data}`); return response.data; } ); .addCase(loadUserAction.fulfilled, (draft, action) => { draft.loadUserLoading = false; draft.loadUserDone = true; draft.me = action.payload || null; }) 툴킷쪽은 이런식으로 작성했습니다.
-
미해결[리뉴얼] React로 NodeBird SNS 만들기
CSR이더라도 메인 홈페이지는 검색이 되는게 맞죠?
제로쵸 선생님 너무 궁금해서 질문드립니다 ㅜ흔히 CSR은 SEO 최적화가 어렵다고 하는데 최적화가 어렵지 기본적인 메인 홈페이지는 검색이 되는게 맞죠?시작이 되는 index.html의 소스의 <head></head> 태그안에 meta 태그 속성 중 네임과 컨텐트,그리고 타이틀 태그로 인해서, 기본적인 메인 홈페이지는 검색이 되는것 맞나요?