본문 바로가기

오류해결

strapi 호스팅 중 발생한 에러 처리

strapi 호스팅 중 발생한 에러 처리 과정을 공유합니다. 저는 digitalocean을 통해 배포했습니다. 오피셜 가이드를 따라하신 분이면 아마 같은 에러가 발생할 것이라 예상됩니다. digitalocean 배포 로그를 보니 heroku를 사용하는 것 같습니다. heroku로 배포하시는 분들에게도 도움이 되었으면 합니다.

Pointing local server at Heroku Postgre produces unexpected error: Could not load js config file config/database.js: Cannot read property ' charAt' of undefined

https://github.com/strapi/strapi/issues/8810#issuecomment-860781901

 

Pointing local server at Heroku Postgre produces unexpected error: Could not load js config file config/database.js: Cannot read

Bug report Describe the bug When installing the strapi blog template locally according to the most recent documentation everything works great. I can configure Heroku with a PostgreSQL database and...

github.com

에러 원인은 공식 가이드대로 했을 경우, 빌드 타임에 ENV.DATABASE_URL 을 가져오지 못하기 때문이라고 합니다. 간단한 해결법은 앱 세팅에 들어가셔서 build command를 다음과 같이 변경해 주시면 됩니다.

DATABASE_URL=$DATABASE_URL NODE_ENV=production npm run build

 

혹은 아래 링크대로 APP spec을 변경해 주셔도 됩니다.

https://forum.strapi.io/t/could-not-load-js-config-file-config-database-js-cannot-read-property-charat-of-undefined/1630/6

 

Could not load js config file config/database.js: Cannot read property ' charAt' of undefined

The problem here is the ENV variable DATABASE_URL is not available during build time. You need to configure your App spec on DO and set the key to RUN_AND_BUILD_TIME

forum.strapi.io

 

Middleware "strapi::session": App keys are required

공식 가이드를 따라 하신 분은 아마 깃헙 레포지토리를 기반으로 deploy를 하도록 설정하셨을 것입니다. gitignore에 .env가 포함되어서 레포지토리에 올라가지 않기 때문에 발생하는 문제입니다. 다만 절대 .env파일을 깃헙에 올리거나, server.js에 하드코딩 하시면 안됩니다.

 

.env 파일에 있는 APP_KEYS를 복사하신 후, 대쉬보드의 앱 세팅에 가셔서 App-Level Environment Variables에 추가해 주시면 됩니다.