JSON SERVER란 ?
아주 간단한 DB와 API 서버를 생성해주는 패키지.
실제 API 서버 구축되기 전까지 임시 사용할 mock 데이터 만들기 위함.
yarn add json-server
로 설치yarn start
yarn json-server --watch db.json --port 3001
두 가지 각자 따로 실행. 각자 실행해줘야 리액트와 제이슨 서버가 통신 가능함.
{
"todos": [
{
"id": 1,
"title": "json-server",
"content": "json-server를 배워봅시다."
}
]
}
배포
cross-env 설치
scripts": {
"start": "node server",
"start:dev": "cross-env NODE_PATH=src react-scripts start",
"build": "cross-env NODE_PATH=src react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject",
"heroku-postbuild": "cross-env NODE_PATH=src npm run build"
},
// 원래코드
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
yarn build
node server