-
카테고리
-
세부 분야
백엔드
-
해결 여부
미해결
ENOENT: no such file or directory, stat \public\index.html
23.06.07 18:17 작성 23.06.07 18:23 수정 조회수 737
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를 요청해도 마찬가지입니다.)
어떤 부분에서 잘못되었는지 감이 안 잡히네요...
힌트라도 주시면 감사하겠습니다!
답변을 작성해보세요.
0

조현영
지식공유자23.06.07 23:53
아... 지금에서야 생각난 게 있는데 그냥 localhost:3095 접속하시면 페이지 뜨지 않나요(프론트미들웨어는 제 코드 그대로 두시고)?? nest-typeorm 폴더는 프론트 서버를 따로 켤 필요가 없습나다
nest-typeorm 폴더는 완성본입니다. 처음부터 따라하는 용도가 아니라서요.

Jack
질문자23.06.08 09:52
예 페이지가 뜹니다.
페이지가 처음 시작되면 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파일이 옵니다.
세심하게 봐주셔서 감사드립니다.

Jack
질문자23.06.08 12:39
네
{"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

조현영
지식공유자23.06.07 18:24
front 폴더로 프론트 실행하신거면 frontMiddleware와 아무 상관이 없습니다.
지금 배포단계 아닌가요?? 배포단계에서는 front 폴더에서 빌드한 파일을 nest-tyeporm의 public에 집어넣으면 됩니다.
nest-typeorm은 제걸 의미하시는건가요? 아니면 직접 만드신건가요? dist 폴더 구조는 어떤 모양인가요?

Jack
질문자23.06.07 20:49
배포단계는 아닙니다. 수업을 듣다가 도중에 못 들어서 다시 개발 단계부터 하나씩 하고 있습니다.
nest-typeorm은 강사님께서 만드신 걸로 했습니다. dist 폴더 구조는 이렇게 되어있습니다.
강사님의 깃헙에 있는 그대로 입니다.
이제 ENOENT: statusCode":404, no such file or directory, stat \public\index.html'
이 에러는 발생하지 않습니다.
그런데 코드를 실행 하면 로그인을 하지도 않았는데 /workspace/sleact/channel/
페이지로 바로 가버립니다. 로그인 페이지를 거치지 않구요.
userData가 있기 때문에 리다이렉트를 시키는 것으로 보여서
userData를 콘솔로 찍어보면
이런식으로 나오고
로그인 됨이 찍힙니다.
바쁘신데 감사합니다.

조현영
지식공유자23.06.07 20:54
질문을 배포 강좌에 달으셔서 배포단계인줄 알았습니다.
localhost:3090/api/users 로 지금 프론트에서 서버로 요청보내는 것인데 백엔드 콘솔에는 아무 기록이 안 찍히나요?
만약 그렇다면 프론트쪽에서 localhost:3095로 수정을 해야할 것 같긴 하네요.

Jack
질문자23.06.07 22:29
백앤드 콘솔에는 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

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

Jack
질문자23.06.07 23:29
네 백앤드 처음 시작할 때 나오는 로그는
[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
스웨거는 이렇게 보여드리는 게 맞는지 모르겠어서 스크린샷 첨부드립니다. 양해 부탁드립니다.
답변 2