개발 일지 - narae-develop/portfolio GitHub Wiki

9/23일자 로그

서버 배포 과정

npm install
npm run build:cave:admin && npm run build:cave:api && npm run build:cave:web
pm2 kill
killall node
pm2 start npm --name admin -- run start:cave:admin
pm2 start npm --name web -- run start:cave:web
pm2 start npm --name api -- run start:cave:api

서버 빌드 오류 해결과정

npm 모듈을 무조건 install 하고 시작하는데 이때 npm rebuild 하라는 오류가 나옴 npm rebuild를 통해 npm 모듈을 재설치함

이후 로컬에서 테스트 시엔 문제가 안되었으나 cave 서버로 옮기니 새 컴포넌트의 임포트 구문에서 파일 대소문자를 지키지 않아 오류가 발생함(또한 vue파일을 모듈로 인식을 해주지 않기도 했음)

-import DatePickerPeriod from '../../common/components/DatePickerPeriod';
-import DatePickerMemo from '../../common/components/DatePickerMemo';
+import DatePickerPeriod from '../../common/components/DatepickerPeriod.vue';
+import DatePickerMemo from '../../common/components/DatepickerMemo.vue';

수정해주니 이번에는 암호화 모듈 부분에서 해당 오류가 발생함

Error: The module '/Users/api/node_modules/bcrypt/lib/binding/bcrypt_lib.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 46. This version of Node.js requires
NODE_MODULE_VERSION 57. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

이는 해당 구문을 통해 수정함

npm rebuild bcrypt --update-binary

9/24일자 로그

기본적으로 어떠한 통신이 오고 갔고 응답코드는 어떤식으로 떨어지는 것은 아래 명령어들로 확인 가능함

pm2 monit
pm2 log

단, url과 응답코드만 보이기에 오류문이 보이지 않음 오류문은 winston에 의해 예외처리를 통해 찍어주면 /data/www/development/source/logs 레벨에 따라 쌓이게 됨

기존에는 api 통신이 들어오면 콜백함수내에서만 예외처리를 했는데(이또한 콘솔로 찍어내거나 하는게 전부임) 이는 업로드 같은 기능이 있는 api의 경우 콜백을 던지기 전에 upload multer 기능을 수행하는 데 이는 감지해내지 못하는 현상이 발생했다. 이는 업로드 기능을 수행하기 전에 try ~ catch 구문으로 처리해주어 업로드 시 문제되는 로그까지 쌓이도록 개선했다.

-        router[api.method](api.url, upload, cb);
+        router[api.method](api.url, async (ctx, next) => {
+          try {
+            await upload(ctx, next);
+            await cb(ctx, next);
+          } catch (e) {
+            ServerUtil.logger.error('initApi image > ', e);
+            ctx.throw(500, e);
+          }
+        });

그리고 winston 로그 위치에 가서 확인해본 결과

{"level":"error","timestamp":"2019-09-24 23:40:15.841","message":"\"  CredentialsError: Missing credentials in config\\n      at IncomingMessage.<anonymous> (/data/www/development/source/node_modules/aws-sdk/lib/util.js:888:34)\\n      at IncomingMessage.emit (events.js:203:15)\\n      at IncomingMessage.EventEmitter.emit (domain.js:448:20)\\n      at endReadableNT (_stream_readable.js:1145:12)\\n      at process._tickCallback (internal/process/next_tick.js:63:19)\""}

뜨는 것을 확인함 s3는 기본적으로 secret_access_key가 필요함 이는 ~/.aws/credentials에 정의해주어야 함

[default]
aws_access_key_id=
aws_secret_access_key=
⚠️ **GitHub.com Fallback** ⚠️