<aside> 🧑🏻🏫 프로젝트에 추가적으로 환경 설정을 하고 싶을 때 package.json 과 같은 위치인 루트 경로에 **"next.config.js"**라는 이름으로 설정파일을 추가하고 활용합니다.
</aside>
NODE_ENV
**로 환경을 확인하여 api url을 분기할 수 있습니다.development
"이고, "yarn build"로 실행하면 env는 "production
"이 됩니다.const env = process.env.NODE_ENV;
switch (env) {
case 'development':
API_URL = '<http://localhost:8080>;
break;
case 'staging':
API_URL = '<https://stg.api.evereathing.com>';
break;
case 'production':
API_URL = '<https://api.evereathing.com>';
break;
default:
API_URL = '<https://api.evereathing.com>';
}
module.exports = {
env: {
API_URL
}
};
"scripts": {
"dev": "next",
"build:staging": "NODE_ENV=staging next build",
"build": "next build",
"start": "next start -p 80"
},
// utils/config.ts
export const API_URL = process.env.API_URL;
// API_URL 사용 예제
import { API_URL } from 'utils/config';
//생략
fetch(`${API_URL}/users`).then().then();