• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

브라우저에 localhost:3030 입력시

22.09.23 01:49 작성 조회수 372

0

제로초님의 Github 을 보기도 했고 영상을 정지하고 따라 해보기도 했습니다만

브라우저에서 localhost:3030 을 입력해서 접속을 하면 화면 캡처 2022-09-23 014322.jpg위 스크린샷과 같이 나오게 됩니다.

에러코드500 은 서버쪽 문제이기에 에러메시지를 확인해보면

 Info  Webpack is building your sources...

webpack 5.74.0 compiled successfully in 656 ms
[Nest] 27340  - 2022. 09. 23. 오전 1:40:04   ERROR [ExceptionsHandler] secret option required for sessions
Error: secret option required for sessions
    at session (E:\Github\Slack\anest\dist\main.js:2474:12)
    at Layer.handle [as handle_request] (E:\Github\Slack\anest\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:328:13)
    at E:\Github\Slack\anest\node_modules\express\lib\router\index.js:286:9
    at Function.process_params (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:346:12)
    at next (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:280:10)
    at cookieParser (E:\Github\Slack\anest\node_modules\cookie-parser\index.js:57:14)
    at Layer.handle [as handle_request] (E:\Github\Slack\anest\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:328:13)
    at E:\Github\Slack\anest\node_modules\express\lib\router\index.js:286:9
[Nest] 27340  - 2022. 09. 23. 오전 1:40:04   ERROR [ExceptionsHandler] secret option required for sessions
Error: secret option required for sessions
    at session (E:\Github\Slack\anest\dist\main.js:2474:12)
    at Layer.handle [as handle_request] (E:\Github\Slack\anest\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:328:13)
    at E:\Github\Slack\anest\node_modules\express\lib\router\index.js:286:9
    at Function.process_params (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:346:12)
    at next (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:280:10)
    at cookieParser (E:\Github\Slack\anest\node_modules\cookie-parser\index.js:57:14)
    at Layer.handle [as handle_request] (E:\Github\Slack\anest\node_modules\express\lib\router\layer.js:95:5)
    at trim_prefix (E:\Github\Slack\anest\node_modules\express\lib\router\index.js:328:13)
    at E:\Github\Slack\anest\node_modules\express\lib\router\index.js:286:9

이라는 에러메시지를 출력하게 되는데
혹시나 싶어서 구글링을 해보았는데 예전에 다른강좌 에서 답변을 남기신것또한 참고를 해보았으나 해결이 되지 않아 질문 남김니다.
에러 해결을 위해 어느부분을 보면 좋을까요?

답변 1

답변을 작성해보세요.

1

.env 파일에 COOKIE_SECRET 넣으세요

Cliche님의 프로필

Cliche

질문자

2022.09.23

오 안주무시고 계셨군요... 좀더 찾아보니


  app.use(
    session({
      resave: false,
      saveUninitialized: false,
      secret: 'SECRET',
      cookie: {
        httpOnly: true,
      },
    }),
  );

이라고 작성하면 고쳐졌습니다만.. 정확한 해결책은 아니었군요... 감사합니다.

Cliche님의 프로필

Cliche

질문자

2022.09.23

아그리고 깃헙에서 .env 파일은 어디서 볼 수 있을까요?

.env는 깃헙에 올리면 안 되는 파일이라 제외했습니다. 파일 만드시고 내부에

COOKIE_SECRET=secret

적으시면 됩니다.

Cliche님의 프로필

Cliche

질문자

2022.09.23

아~ 그렇군요.. 해결감사합니다.

강좌를 따라 가고 있는데 보면 처음에 main.ts 에 소스를 작성한뒤 그뒤에는 작성을 안하고 이번 강좌에 다시 main.ts에 소스코드를 작성을 하는데 기존에 강좌내에서 작성하지 않은 소스코드들이 영상에선 이미 작성되어서 에러가 발생한것 같습니다.