묻고 답해요
164만명의 커뮤니티!! 함께 토론해봐요.
인프런 TOP Writers
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
error_code : Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.ts(2339)
안녕하세요! 저와 같은 수강생 여러분, 반갑습니다.분명 저와 같은 에러를 겪고 분투하는 사람을 위해서 제 경험을 공유 드립니다. 저 같은 경우 선생님 코드를 그대로 따라 진행을 했었는데요.특히나 CustomDecoration 부분에 있어서 그대로 따라 진행을 했습니다. 정확히 이 부분에서 에러가 발생을 하더라구요.return request.user as CatCurrentDto; 에러의 내용은 아래와 같습니다.Property 'user' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.ts(2339) 해결방안은 선생님이 보여주신 nestJS의 공식문서를 참고해서 다시 적어보았는데요. Request를 제거해주시면 저 부분이 잡힙니다. 버전이 자꾸 바뀌기때문에 매개변수, 메소드, 각각의 요구되는 필드값 또한 바뀌는것 같습니다. 무언가 잘 안될때는 제공해주신 공식문서 찾는것도 좋은 방법인거 같습니다. 저와 같은 에러를 만나신분에게 조금이나마 도움이 되었음좋겠습니다. 아래는 전체 로직 입니다. [user.decorator.ts] -> 제공된 소스코드 수정한 코드import { CatCurrentDto } from './../../cats/dto/cats.current.dto'; import { createParamDecorator, ExecutionContext } from '@nestjs/common'; export const CurrentUser = createParamDecorator( (data: unknown, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest(); return request.user as CatCurrentDto; }, ); [user.decorator.ts] -> 제공된 소스코드import { CatCurrentDto } from './../../cats/dto/cats.current.dto'; import { Request } from 'express'; import { Cat } from '../../cats/cats.schema'; import { createParamDecorator, ExecutionContext } from '@nestjs/common'; export const CurrentUser = createParamDecorator( (data: unknown, ctx: ExecutionContext) => { const request: Request = ctx.switchToHttp().getRequest(); return request.user as CatCurrentDto; }, );
-
미해결[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
파일명 짓고 구분하기가 어렵습니다
수업 거의 다 듣고 포트폴리오 만드는 중에 질문드립니다. fetchBoards로 게시판을 불러올때 리턴 객체명을 어떻게 해야할지 모르겠습니다. 예를 들어, board[], paging 값이 두개 리턴이 된다고 했을때 dto폴더에 select-board.output.ts 객체 파일을 만들어주면 될까요? 아니면 board[], paging 형태로 내보내는것은 나쁜 방식일까요? 웬만하면 프론트가 아니라 백에서 처리해서 내보내려고 합니다. 이런식으로 폴더 구분이랑 파일 이름 짓기가 모호한 경우가 많은데 여기에 초점을 맞춘다고 시간을 허비하지말고 구분만 잘해놓는게 좋을까요?
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
VScode postgresql 익스플로러 'Cannot get password' 에러
안녕하세요 강의 잘 보고 있습니다!다름이 아니고 VScode에서 postgres 익스플로러로 DB연결을 해주려는데 자꾸 오른쪽 밑에 'Cannot get password'라는 에러가 발생해서 연결이 되지 않습니다... yaml파일이랑 app.module도 잘 확인했는데 해당 에러때문에 DB 연결이 안됩니다. 확인 부탁드릴게요,, 캡쳐본입니다. post로 바꿔고 해봐서 현재 post입니다.
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
NodeJS 는 왜 싱글 스레드라고 불리는가요?
안녕하세요! 개발을 시작한지 얼마되지 않은 개발자입니다. 수업의 내용을 조금 인용하면 "nodeJS 는 싱글 스레드 모델이고, 이벤트 룹이 앞단에서 nonBlocking 요청 빠르게 수행하고 만일 Blocking 요청이 들어온다면 워커 스레드에 넘긴다. " 라고 이해했습니다.하지만 워커 스레드를 사용하게된다면 그것이 싱글 스레드라는 이름에 맞는건지 의구심이 듭니다. 단순히 이벤트 룹이라는 특정 스레드가 앞단에서 Blocking 요청과 nonBlocking 요청을 구분해서 처리를 하기에 싱글 스레드라는 말이 나온건가요?그리고 이벤트 룹이 Blocking 요청과 nonBlocking 요청을 나누는 기준 또한 궁금합니다.마지막으로 구글링을 하며 본 정보에 의하면 JavaScript 가 싱글 스레드 기반의 언어이고, NodeJS는 스레드 풀을 미리 생성하여 워커 스레드들을 미리 생성해 둔 뒤, 각 워커 노드에서 JavaScript 를 실행하여 멀티 스레드를 가능하게 한다는 글을 보았는데 이 내용이 맞다면 NodeJS 는 싱글 스레드 기반 프레임워크가 아닌것으로 받아드려도 괜찮을까요?
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
에러가 뜨네요 수강 강의 내용에도 전체 내용이 없어서 안되네요 전체 코드는 제공이 안되나요??
import { ApolloServer } from '@apollo/server' import { startStandaloneServer } from '@apollo/server/standalone' const typeDefs = `#graphql input CreateBoardInput { writer: String title: String contents: String } type MyResult { number: Int writer: String title: String contents: String } type Query { #fetchboards: MyResult #객체 1개를 의미 fetchboards: [MyResult] # 배열 안에 객체 1개 이상을 의미! } type Mutation { # createBoard(writer: String, title: String, contents: String): String createBoard(createBoardInput: CreateBoardInput!): String }`; const resolvers = { Query: { fetchBoards: (parent, args, context, info) => { // 1. 데이터를 조회하는 로직 => DB에 접속해서 데이터 꺼내오기 const result = [ { number: 1, writer: '철수', title: '제목입니다~~', contents: '내용이에요@@@', }, { number: 2, writer: '영희', title: '영희 제목입니다~~', contents: '영희 내용이에요@@@', }, { number: 3, writer: '훈이', title: '훈이 제목입니다~~', contents: '훈이 내용이에요@@@', }, ]; // 2. 꺼내온 결과 응답 주기 return result; }, }, Mutation: { createBoard: (_, args) => { // 1. 브라우저에서 보내준 데이터 확인하기 console.log(args); console.log("=========================") console.log(args.createBoardInput.writer) console.log(args.createBoardInput.title) console.log(args.createBoardInput.contents) // 2. DB에 접속 후, 데이터를 저장 => 데이터 저장했다고 가정 // 3. DB에 저장된 결과를 브라우저에 응답(response) 주기 return "게시물 등록에 성공하였습니다!!"; }, }, }; const server = new ApolloServer({ typeDefs: typeDefs, resolvers: resolvers, cors: true, // 모든 사이트 허용하고 싶을 때 // cors: { origin: ["https://naver.com", "https://daum.net"] } // 특정 사이트만 지정하고 싶을 때 }); startStandaloneServer(server) // 4000node_modules/@graphql-tools/schema/esm/addResolversToSchema.js:62 throw new Error(`${typeName}.${fieldName} defined in resolvers, but not in schema`); at file:///Users/youssipro/Desktop/project/backend/class/section03/03-06-graphql-api-apollo-server-board/index.js:78:16
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
typeOrm 1:N N:1 관련 질문입니다.
너무 단순한 것 같은데, 몇시간 확인해봐도 해결이 되지 않아서 이렇게 질문드립니다.post 로 1:N을 생성해서 확인해 보면, 아래 이미지 처럼 post에 빈배열이 나옵니다.get 요청, relations 은 아래와 같습니다. 강의를 보면서 작성한 코드입니다. 이전 내용인 profile 은 잘 되는데...post 1:N 은 무엇이 문제일까요...?
-
해결됨[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
createQueryRunner는 undefined속성을 읽을 수 없다
const qr = this.dataSource.createQueryRunner();ERROR [ExceptionsHandler] Cannot read properties of undefined (reading 'createQueryRunner')TypeError: Cannot read properties of undefined (reading 'createQueryRunner') at TransactionInterceptor.intercept (C:\Users\Administrator\Desktop\cf_sns\src\common\interceptor\transaction.interceptor.ts:21:32)이 에러가 떠서 postman으로 테스트를 진행하지 못하고있습니다. dataSource도 typeorm에서 import 해서 사용했는데 컨트롤러에서 트랜잭션을 사용할때는 됐다가 인터셉터로 따로 빼서 사용하려고할 때 발생한 오류입니다.
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
jwt를 따로 연습하고 있는데 env를 못읽는 것 같습니다.
import { Module } from '@nestjs/common'; import { AuthController } from './auth.controller'; import { AuthService } from './auth.service'; import { ConfigModule } from '@nestjs/config'; import { PassportModule } from '@nestjs/passport'; import { JwtModule } from '@nestjs/jwt'; import { JwtStrategy } from 'src/auth/jwt/jwt.strategy'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true, envFilePath: `.env.${process.env.NODE_ENV}`, }), PassportModule.register({ defaultStrategy: 'jwt', session: false }), JwtModule.register({ secret: process.env.JWT_SECRET, signOptions: { expiresIn: '1y' }, }), ], controllers: [AuthController], providers: [AuthService, JwtStrategy], }) export class AuthModule {}이게 auth.module.ts 파일입니다import { Injectable } from '@nestjs/common'; import { PassportStrategy } from '@nestjs/passport'; import { ExtractJwt, Strategy } from 'passport-jwt'; @Injectable() export class JwtStrategy extends PassportStrategy(Strategy) { constructor() { super({ jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(), ignoreExpiration: false, secretOrKey: process.env.JWT_SECRET, }); } async validate() {} }여기서 문제가 일어났습니다. process.env.JWT_SECRET 이 것을 읽지 못합니다.NODE_ENV="development" JWT_SECRET="secret" PORT=8000.env.development 파일도 root폴더에 잘 있습니다. 무엇이 문제인지 잘 모르겠습니다
-
해결됨[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
강의 ppt
강의 ppt는 따로 받을수는 없나요?
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
postPosts의 req.user.id 컴파일 에러?
postPosts 컨트롤러까지 요청이 들어왔다면 Request 객체에 user 프로퍼티가 있는 것은 확실한데타입스크립트 컴파일러가 인식을 못하는 것 같아요.앱 실행이 안되는데 어떻게 해결해야 할까요...
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
http 모듈
바로 전 강의에서부터 http.을 하면 자동완성이 안되었는데, 그냥 직접 다 작성해서 서버를 실행시키니깐 되긴 되더라구요.근데 이번강의도 http모듈 관련 자동완성을 계속 쓰는 것 같길래 질문드립니다.nodeJs에 기본으로 내장되어있는 모듈이라고 하는데 저는 왜 자동완성이 안될까요?
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
refresh token 재발급과 만료에 대해서
refresh token을 재발급 하기 위한 작업 과정에 대해 궁금한 것이 있어서 질문드립니다.저는 access token이 만료되면 refresh token을 통해 재발급을 받으려고 시도하고,이때 refresh token마저 만료된 상태라면 다시 로그인 하여 새로운 access token과 refresh token을 발급받아야 한다고 생각하고 있었습니다.그런데 refresh token을 재발급하는 로직도 강의 내용에 있더라구요.강의에서 refresh token이 만료되면 /auth/token/refresh api로 refresh token을 재발급 받으면 된다라고 설명해주셨는데,만료된 refresh token으로 refresh token을 재발급 받는 건 좀 이상한 것 같아서요.아니면 refresh token이 만료되지 않았는데 refresh token을 재발급 해야 하는 요청이 따로 있을까요?
-
해결됨[리뉴얼] 맛집 지도앱 만들기 (React Native & NestJS)
프로젝트 설치 npx
npx react-native@latest init MatzipApp npx: 541개의 패키지를 19.389초만에 설치했습니다. Unexpected token ? 프로젝트 ruby 버전을 변경하고 프로젝트 npx 설치하는데 해당 오류로 인해 프로젝트 폴더가 생기지 않네요 혹시 해결법이 어떤것일까요?검색해봐도 나오질 않네요
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
x-www-form-urlencoded
x-www-form-urlencoded는프론트로부터form으로 데이터 받을 때 받는 거 아닌가요?
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
access token DB 조회에 관해서
안녕하십니까. 강의 잘 듣고 있습니다 🙂 다름이아니라 궁금한 점이 있어 문의를 드리게 되었습니다.token 계열은 접근시 token 그 자체를 사용하기 때문에 DB 조회가 없어 장점이 있는 로그인 방식이라 생각이 드는데요.1) 강의에서 처럼 access token 을 이용하여 항상 db에서 사용자 데이터를 조회해 온다면 그런 장점이 사라지지 않을까요?2) 또한 부하가 많이 걸리지 않을까요?
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
Ec2로 안하시는 이유가 있을까요?
Ec2로 안하시는 이유가 있을까요?
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
컬럼 애너테이션 update property
update 프로퍼티를 false로 작성했는데도 500에러가 발생하지 않네요response에는 변경된 값이 나옵니다.http://localhost:3000/users/:id{ "id": 2, "title": "null0", "createdAt": "2024-03-24T23:59:11.774Z", "updatedAt": "2024-03-24T23:59:11.774Z", "version": 1, "additionalId": "a320e186-a44a-4dda-9af3-9cd52af4155c" }그런데 DB에 가보면 또 값은 변경되어 있지 않더라구요 2번 user의 title 값은 null이 그대로 찍혀있습니다.왜 500에러가 발생하지 않는건가요?
-
미해결탄탄한 백엔드 NestJS, 기초부터 심화까지
ERROR [ExceptionsHandler] this.validate is not a function 무슨 에러일까요 ㅠ
안녕하세요 postman에서 login 요청을 보내려고 할때 터미널에서 ERROR [ExceptionsHandler] this.validate is not a function 라고 오류가 납니다 validate를 함수로 작성해주었는데 이러한 오류가 나서 어떻게 해결해야 할지 고민입니다.
-
미해결[코드팩토리] [초급] NestJS REST API 백엔드 완전 정복 마스터 클래스 - NestJS Core
postman 환경변수 저장하기 질문있습니다.
API 응답 받고 포스트맨의 Tests 탭에코드를 저장했는데 Environments 탭의 accessToken 변수에 값이 안담기더라구요 혹시 몰라 Globals 탭에서확인했는대도 거기에도 없던데 왜 이런지 알 수 있을까요? API TestResults 에는 성공이라는 메시지는 나옵니다.
-
미해결[코드캠프] 부트캠프에서 만든 고농축 백엔드 코스
restoreAccessToken 이라는 함수를 새로만드는 이유가 있을까요??
안녕하세요. 강의 내용중에 restoreAccessToken이라는 함수를 만드는데 내용이 getAccessToken을 리턴해주는 함수입니다.restoreAccessToken({ user }: IAuthServiceRestoreAccessToken): string { return this.getAccessToken({ user }); } getAccessToken({ user }: IAuthServiceGetAcessToken): string { return this.jwtService.sign( { sub: user.id }, { secret: '나의비밀번호', expiresIn: '10s' }, ); }인터페이스도 두번 작성하게 되는데export interface IAuthServiceRestoreAccessToken { user: IAuthUser['user']; } export interface IAuthServiceGetAcessToken { user: User | IAuthUser['user']; } 이런경우에는 그냥 restoreAccessToken이라는 함수를 새로 안만들고, getAccessToken을 바로 사용하는게 코드의 중복을 제거하는 측면에서 더 좋다고 생각하는데,restoreAccessToken이라는 함수를 새로 만드는 이유가 있을까요??