Frontend/└vue

[Netlify] 서버리스 배포

SOLYI 2021. 10. 22. 18:16
반응형

netlify.com
login - functions

https://docs.netlify.com/functions/overview/?_ga=2.6479674.907396097.1634890312-596079682.1634890312

netlify.toml 파일 생성 

[build]
  functions = "functions"


functions/hello.js 파일 생성

exports.handler = async function (event, context) {
  return {
    statusCode: 200,
    body: JSON.stringify({
      name: 'choi-solyi',
      age: 31,
      email: 'choi-solyi@naver.com'
    })
  }
}



--> https://unruffled-jang-821fdf.netlify.app/.netlify/functions/hello
https://cli.netlify.com/netlify-dev

netlify.toml 파일 수정

[build]
  command = "npm run build"
  functions = "functions" #서버리스 함수가 작성된 디렉토리 지정
  publish = "dist"  #프로젝트의 결과 디렉토리

[dev]
  framework = "#custom" 
  command = "npm run dev"
  targetPort = 8081
  port = 8888
  publish = "dist"
  autoLaunch = true  # 서버가 준비되면 자동으로 브라우저를 오픈할것인지




@npm 설치
npm i -D netlify-cli

반응형