HomeAboutMeBlogGuest
© 2025 Sejin Cha. All rights reserved.
Built with Next.js, deployed on Vercel
🧐
Sonny
/
next.config.js에서 설정한 사항을 클라이언트에서 가져오는 방법 (getConfig())
next.config.js에서 설정한 사항을 클라이언트에서 가져오는 방법 (getConfig())
next.config.js에서 설정한 사항을 클라이언트에서 가져오는 방법 (getConfig())

next.config.js에서 설정한 사항을 클라이언트에서 가져오는 방법 (getConfig())

날짜
Jul 2, 2022
  • 환경변수는 node.js에서 사용 시, 서버 사이드이기 때문에 사용가능
  • 클라이언트에서는 환경 변수를 바로 사용 불가 ⇒ .env가 한번에 클라이언트까지 전달되지 않음
  • getConfig()는 next.js에서 config에 정의된 값을 사용할 수 있게 해줌
// next.config.js module.exports = { reactStrictMode: true, publicRuntimeConfig: { apiKey: process.env.publicApiKey || '', authDomain: process.env.FIREBASE_AUTH_HOST || '', projectId: process.env.projectId || '' } }
// example.ts import getConfig from 'next/config'; const { publicRuntimeConfig } = getConfig(); // ...