본문 바로가기
개발일지/NextJS

NextJS에서 API 디렉토리를 사용할 수 없는 이유

by 한삐 2023. 5. 1.
728x90

NextJS는 pages/api 디렉토리를 통해 백엔드에 대한 처리를 수행할 수 있다.

하지만 정적으로 배포된 사이트(ex. 블로그 등)에서는 pages/api 등과 같은 동적 로직은 지원되지 않기 때문에 api 디렉토리를 사용할 수 없다.

 

정적 배포 방법

// package.json
// NextJS 13.3 이전 버전
"scripts": {
    "dev": "next dev",
    "start": "next start",
    "lint": "next lint",
    "build": "next build && next export", // ## 정적 배포
    "predeploy": "npm run build",
    "deploy": "touch out/.nojekyll && gh-pages -d out --dotfiles"
  },
  
  
// next.config.js
// NextJS v13.3 ~
/**
 * @type {import('next').NextConfig}
 */
const nextConfig = {
  output: 'export',
}

module.exports = nextConfig

 


https://nextjs.org/docs/advanced-features/static-html-export

 

Advanced Features: Static HTML Export | Next.js

Export your Next.js app to static HTML, and run it standalone without the need of a Node.js server.

nextjs.org

 

 

 

728x90

댓글