๐Ÿ“Œ๋ชฉ์ฐจ

์†Œ๊ฐœ

๋ง›์ด ์–ด๋•Œ

๐Ÿ—“ 2022.07.21 ~ 2022.08.15

FE 4๋ช…, BE 4๋ช…์œผ๋กœ ๊ตฌ์„ฑ๋œ ํŒ€ ํ”„๋กœ์ ํŠธ๋กœ ์ปค์Šคํ…€ ๋ฉ”๋‰ด์— ํฅ๋ฏธ๊ฐ€ ์žˆ๋Š” ์‚ฌ์šฉ์ž๋“ค์ด ์ž์‹ ์˜ ์ปค์Šคํ…€ ๋ฉ”๋‰ด๋ฅผ ๊ณต์œ ํ•˜๊ณ  ๋ฆฌ๋ทฐํ•  ์ˆ˜ ์žˆ๋Š” SNS ํ”Œ๋žซํผ ์ž…๋‹ˆ๋‹ค.

๊ตฌํ˜„

TypeScript React.js Next.js Emotion Axios Git Vercel React-query Recoil Vercel

๋‹ด๋‹น ์—…๋ฌด

1. nextConfig ์„ค์ •

API๊ฐ€ ์˜คํ”ˆ์†Œ์Šค๊ฐ€ ์•„๋‹ˆ๊ธฐ์— nextConfig์˜ rewrites๋ฅผ ํ†ตํ•ด API๋ฅผ ์€๋‹‰ํ•˜๋„๋กํ–ˆ๊ณ , ์บ์‹ฑ ์ด๋ฏธ์ง€๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ฏธ์ง€ ๋„๋ฉ”์ธ ์ฃผ์†Œ๋ฅผ ๋“ฑ๋กํ•ด์คฌ์Šต๋‹ˆ๋‹ค.

๋˜, ์ด๋ฅผ ํ†ตํ•ด ํ”„๋ก ํŠธ์—”๋“œ ์„œ๋ฒ„๋ฅผ ํ”„๋ก์‹œ ์„œ๋ฒ„๋กœ ์‚ฌ์šฉํ•ด HTTPS๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ํ”„๋ก ํŠธ์—”๋“œ ์„œ๋ฒ„์—์„œ HTTP ๋ฐฑ์—”๋“œ API๋ฅผ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.

const API_KEY = process.env.NEXT_PUBLIC_API_URL

const nextConfig = {
  reactStrictMode: true,
  swcMinify: true,
  images: {
    domains: [
      'user-images.githubusercontent.com',
      'masiottae-image-bucket.s3.ap-northeast-2.amazonaws.com'
    ]
  },
  async rewrites() {
    return [
      {
        source: '/api/:path*',
        destination: `${API_KEY}/:path*`
      }
    ]
  }
}

module.exports = nextConfig

2. axios instance ์ƒ์„ฑ

nextConfig์˜ rewrites๋ฅผ ํ†ตํ•ด API๋ฅผ ์€๋‹‰ํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, axios instance์˜ baseUrl์„ '/api'๋กœ ๋‘๊ณ  '/api' ๋’ท ๋ถ€๋ถ„๋งŒ ๋ฐ›์•„ url๋กœ ๋„˜๊ธฐ๋„๋ก ํ–ˆ์Šต๋‹ˆ๋‹ค.