inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

Slack 클론 코딩[백엔드 with NestJS + TypeORM]

배포 준비하기(빌드, pm2, cross-env)

ENOENT: no such file or directory, stat \public\index.html

3009

Jack

작성한 질문수 11

0

안녕하세요. 강사님

지금 sleact db를 생성하였고 table도 다 생성된 상태입니다.

nest-typeorm 폴더와 front 폴더 를 둘 다 실행시키면

 

 

 api/users api를 요청할 때

ENOENT: statusCode":404, no such file or directory, stat \public\index.html'

이러한 에러가 발생합니다.

 

middlewares/frontend.middleware.ts 파일의 경로가 잘못되어 있나 해서

 res.sendFile(
        path.join(__dirname, '..', '..', '..', 'public', 'index.html'),
      );

      res.sendFile(path.join(__dirname, '../', 'public', 'index.html'));

로 바꿔주었더니

api 로그인 페이지로 가지 않고 바로 workspace로 가집니다.

response도 html파일로 옵니다. (어떠한 api를 요청해도 마찬가지입니다.)

 

어떤 부분에서 잘못되었는지 감이 안 잡히네요...

힌트라도 주시면 감사하겠습니다!

 

node.js express nestjs typeorm

답변 2

0

제로초(조현영)

아... 지금에서야 생각난 게 있는데 그냥 localhost:3095 접속하시면 페이지 뜨지 않나요(프론트미들웨어는 제 코드 그대로 두시고)?? nest-typeorm 폴더는 프론트 서버를 따로 켤 필요가 없습나다

nest-typeorm 폴더는 완성본입니다. 처음부터 따라하는 용도가 아니라서요.

0

Jack

예 페이지가 뜹니다.

페이지가 처음 시작되면 http://localhost:3090/workspace/sleact/channel/일반

이라는 페이지로 이동합니다.

그리고 프론트 페이지에서 channelData.map is not a function 이라는 에러가 발생합니다.

이게 userData가 html파일로 들어오니까 userData가 있음으로 login했다고 판단해서 프론트쪽에서는

http://localhost:3090/workspace/sleact/channel/일반

이 페이지로 리다이렉트 시킴으로 발생하는 에러인 것 같습니다.

로그인 하지 않았는데 위에있는 채널 페이지로 갔는데 channelsData가 없으니까 발생하는 에러 같습니다.

 

postman으로 요청을 해도 같은 html파일이 옵니다.

 

세심하게 봐주셔서 감사드립니다.

 

 

0

제로초(조현영)

아뇨 그냥 localhost:3095로 접속해보세요. 3090 말고요

0

Jack

{"statusCode":404,"message":"ENOENT: no such file or directory, stat 'C:\\Users\\jack\\Desktop\\zerocho reactcode\\sleact\\public\\index.html'"}

가 뜹니다.

app.module.ts에 있는 이 미들웨어를 주석처리 하니 잘 됩니다. 감사합니다!

consumer.apply(FrontendMiddleware).forRoutes({
      path: '/**',
      method: RequestMethod.ALL,
    });

 

 

 

 

0

제로초(조현영)

front 폴더로 프론트 실행하신거면 frontMiddleware와 아무 상관이 없습니다.

지금 배포단계 아닌가요?? 배포단계에서는 front 폴더에서 빌드한 파일을 nest-tyeporm의 public에 집어넣으면 됩니다.

nest-typeorm은 제걸 의미하시는건가요? 아니면 직접 만드신건가요? dist 폴더 구조는 어떤 모양인가요?

0

Jack

배포단계는 아닙니다. 수업을 듣다가 도중에 못 들어서 다시 개발 단계부터 하나씩 하고 있습니다.

nest-typeorm은 강사님께서 만드신 걸로 했습니다. dist 폴더 구조는 이렇게 되어있습니다.

 

image

강사님의 깃헙에 있는 그대로 입니다.

이제 ENOENT: statusCode":404, no such file or directory, stat \public\index.html'

이 에러는 발생하지 않습니다.

그런데 코드를 실행 하면 로그인을 하지도 않았는데 /workspace/sleact/channel/

페이지로 바로 가버립니다. 로그인 페이지를 거치지 않구요.

userData가 있기 때문에 리다이렉트를 시키는 것으로 보여서

userData를 콘솔로 찍어보면

 

image

이런식으로 나오고

로그인 됨이 찍힙니다.

image

바쁘신데 감사합니다.

 

0

제로초(조현영)

질문을 배포 강좌에 달으셔서 배포단계인줄 알았습니다.

localhost:3090/api/users 로 지금 프론트에서 서버로 요청보내는 것인데 백엔드 콘솔에는 아무 기록이 안 찍히나요?

만약 그렇다면 프론트쪽에서 localhost:3095로 수정을 해야할 것 같긴 하네요.

0

Jack

백앤드 콘솔에는 304 undefined 가 발생합니다.

 

stack overflow에 보니 cache문제라는 것 같기도 해서 캐시를 지워봤는데도 같은 에러가 발생합니다. (304 undefined)

 

[Nest] 15784 - 2023. 06. 07. 오후 10:21:21 LOG [HTTP] GET /api/users 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:21 LOG [HTTP] GET /api/workspaces/sleact/channels 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:21 LOG [HTTP] GET /api/workspaces/sleact/channels/%EC%9D%BC%EB%B0%98/chats?perPage=20&page=1 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:21 LOG [HTTP] GET /api/workspaces/sleact/members 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:21 LOG [HTTP] GET /api/workspaces/sleact/channels/%EC%9D%BC%EB%B0%98/members 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:35 LOG [HTTP] GET /api/users 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:35 LOG [HTTP] GET /api/workspaces/sleact/channels 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

[Nest] 15784 - 2023. 06. 07. 오후 10:21:35 LOG [HTTP] GET /api/workspaces/sleact/channels/%EC%9D%BC%EB%B0%98/chats?perPage=20&page=1 304 undefined - Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36 ::1

0

제로초(조현영)

백엔드 서버 처음 켤 때 나오는 로그를 복사해주세요. 모듈들 연결되는게 주르륵 나올겁니다. 또는 localhost:3095/api 에 접속한 swagger 보여주세요.

0

Jack

네 백앤드 처음 시작할 때 나오는 로그는

[Nest] 18268 - 2023. 06. 07. 오후 11:24:19 LOG [NestFactory] Starting Nest application...

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1344ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] PassportModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] EventsModule dependencies initialized +0ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] ConfigHostModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] AppModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] ConfigModule dependencies initialized +0ms

query: SELECT VERSION() AS version

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmCoreModule dependencies initialized +299ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] TypeOrmModule dependencies initialized +0ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] AuthModule dependencies initialized +4ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] WorkspacesModule dependencies initialized +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] ChannelsModule dependencies initialized +0ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] DMsModule dependencies initialized +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:21 LOG [InstanceLoader] UsersModule dependencies initialized +1ms

init

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [WebSocketsController] EventsGateway subscribed to the "test" message +654ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [WebSocketsController] EventsGateway subscribed to the "login" message +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RoutesResolver] AppController {/}: +9ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/, GET} route +4ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RoutesResolver] UsersController {/api/users}: +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/users, GET} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/users/login, POST} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/users, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/users/logout, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RoutesResolver] WorkspacesController {/api/workspaces}: +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/members, GET} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/members, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/members/:id, GET} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/users/:id, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RoutesResolver] ChannelsController {/api/workspaces}: +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name, GET} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/members, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/members, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/chats, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/chats, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/images, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/channels/:name/unreads, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RoutesResolver] DMsController {/api/workspaces}: +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/dms, GET} route +2ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/dms/:id/chats, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/dms/:id/chats, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/dms/:id/images, POST} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [RouterExplorer] Mapped {/api/workspaces/:url/dms/:id/unreads, GET} route +1ms

[Nest] 18268 - 2023. 06. 07. 오후 11:24:22 LOG [NestApplication] Nest application successfully started +7ms

server listening on port 3095

 

스웨거는 이렇게 보여드리는 게 맞는지 모르겠어서 스크린샷 첨부드립니다. 양해 부탁드립니다.

image

 

image

image

image

 

강의자료는 어디서 다운받나요?

0

110

3

질문 있습니다.

0

294

3

(강의 5:42 질문) providers를 통한 여러 개의 인스턴스 생성 & exports 통한 싱글톤 생성

0

154

2

코드 편집기 확장 프로그램

0

209

2

(질문)비밀 저장소에 접근하기 위한 인증 정보는 로컬 .env에 저장하는지?

0

143

2

(질문)외부 저장소를 통한 환경변수 불러오기 비동기 질문

0

166

3

로그인을 해도 LoggedInGuard쪽에서 false값이 나옵니다.

0

152

2

로그인방법이 고민됩니다.

0

190

2

yarn seed 명령어 실행 시 데이터 삽입 안됨

0

296

4

yarn run db:create 시에 발생하는 데코레이터 오류

0

242

2

npm run db:create 시에 발생하는 decorating 오류

0

231

2

RxJS 디버깅 질문 있습니다.

0

187

3

CacheManager에 대해 질문 있습니다.

0

173

2

로깅은 어떻게 하는게 효율적일까요?

0

224

1

CORS 질문 있습니다.

0

417

2

쿠키 옵션에 대해서 질문 있습니다.

0

184

2

로그아웃 요청이 403 forbidden 에러가 나는데 왜그런걸까요??

0

447

1

401 unauthorized문제

0

286

1

가드의 장점에 대해서 질문이 있습니다.

0

225

1

로그 관리에 대해 질문 있습니다.

0

252

2

CORS 에러 질문 있습니다.

0

318

2

배포 환경 DB 연결 질문 있습니다.

0

411

2

socket io 미 연결 문제 (nest & flutter)

1

1154

3

no elements in sequence 에러 관해서 질문이 있습니다.

0

454

1