반응형
기존 Netlify를 이용하여 웹페이지를 동작하면 개인의 데이터가 보여지는것을 확인할 수 있다.
Get방식으로 파라미터가 전부 보여진다.
따라서 Function 설정을 따로 해주어야한다.
공식문서 url: Build functions with JavaScript | Netlify Docs
Build functions with JavaScript
Netlify builds, deploys, and hosts your frontend. Learn how to get started, find examples, and access documentation for the modern web platform.
docs.netlify.com
기존 프로젝트에 폴더 및 파일 생성
1. 루트경로 -> netlify.toml 파일생성
[functions]
directory = "functions"
2. 루트경로 -> functions 폴더 생성 -> hello.js 파일 생성
exports.handler = async function(event, context) {
return {
statusCode: 200,
// 문자데이터 반환 방법
//body: 'Hello world'
//객체 데이터 반환 방법
body: JSON.stringify({
name: 'HEROPY',
age: 85,
email: 'thesecon@gmail.com'
})
}
}
git hub에 올려두기
1. git add .
2. git commit -m 'Add Netlify functions'
3. git push origin master
netlify에 적용되었는지 확인
url 접근으로 확인 -> 뒷부분에 .netlify/functions/hello 추가
https://epic-albattani-ceea5b.netlify.app/.netlify/functions/hello
반응형
'프론트엔드 > Vue.js' 카테고리의 다른 글
영화 정보 반환 API 만들기 (0) | 2022.01.15 |
---|---|
Netlify-CLI 구성 (0) | 2022.01.15 |
SPA (0) | 2022.01.14 |
검색 정보 초기화 및 페이지 전환 스크롤 위치 복구 (0) | 2022.01.13 |
반복적인 내용을 효율적으로 관리하는 방법: Vuex Helpers (0) | 2022.01.13 |