json-server heroku 배포하기 (에러만났을 때 대처법) WSL2
1. Procfile 만들기 타입스크립트면 ts , 일반이면 js
//Procfile
web: node server.js
2. server 파일 만들기
//server.js
const jsonServer = require("json-server");
const server = jsonServer.create();
const router = jsonServer.router("./db.json");
const middlewares = jsonServer.defaults({
static: "./build",
});
const port = process.env.PORT || 4000;
server.use(middlewares);
server.use(
jsonServer.rewriter({
"/api/*": "/$1",
})
);
server.use(router);
server.listen(port, () => {
console.log("server is running");
});
3. package.json 파일에 script 추가하기
"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"
},
npm i cross-env
설치해야 작동함
https://www.npmjs.com/package/cross-env
cross-env
Run scripts that set and use environment variables across platforms. Latest version: 7.0.3, last published: a year ago. Start using cross-env in your project by running `npm i cross-env`. There are 4820 other projects in the npm registry using cross-env.
www.npmjs.com
4. Heroku CLI 설치
https://devcenter.heroku.com/articles/heroku-cli
The Heroku CLI | Heroku Dev Center
Last updated February 01, 2022 The Heroku Command Line Interface (CLI) lets you create and manage Heroku apps directly from the terminal. It’s an essential part of using Heroku. Install the Heroku CLI Pre-requisites The Heroku CLI requires Git, the popul
devcenter.heroku.com
wsl2 유저는 이것 설치
curl https://cli-assets.heroku.com/install.sh | sh
버전확인 heroku -v
5.본인 프로젝트 마스터 브런치 혹은 default 브런치에서 heroku login
$ git init
$ git add .
$ git commit -am'initial commit'
그 이후
$ heroku create <프로젝트명> # 프로젝트명을 공백으로 하시면 이름이 자동으로 랜덤설정 됩니다.
$ heroku config:set NPM_CONFIG_PRODUCTION=false # devDependency 도 설치하게 설정합니다
$ git push heroku master
에러가 날 경우
heroku buildpacks:set mars/create-react-app
터미널에 입력
참고 블로그
https://bogmong.tistory.com/11
React Application을 Heroku에 Deploy하며 겪은 오류(Error H10)
헤로쿠(Heroku)는 다양한 프로그래밍 언어를 지원하는 PaaS(Platform as a Service)이다. 2007년 처음 개발되었을 때는 루비 언어만 지원했지만 현재는 Java, Node, Scala, Python, Go 등의 다양한 언어를 지원하..
bogmong.tistory.com
https://redux-advanced.vlpt.us/3/09.html
3-9. 최적화 및 히로쿠에 디플로이하기 · GitBook
3-9. 최적화 및 히로쿠에 디플로이하기 최적화 여러분이 리스트를 렌더링 했다면, 그리고 또 그 리스트가 많은 데이터를 보여주게 된다면, 최적화 작업을 진행해주셔야 프로젝트의 성능이 좋아
redux-advanced.vlpt.us
https://github.com/mars/create-react-app-buildpack
GitHub - mars/create-react-app-buildpack: ⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web apps
⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web apps - GitHub - mars/create-react-app-buildpack: ⚛️ Heroku Buildpack for create-react-app: static hosting for React.js web ...
github.com
https://github.com/jesperorb/json-server-heroku#deploy-to-heroku
GitHub - jesperorb/json-server-heroku: Deploy json-server to Heroku & Glitch & Azure
Deploy json-server to Heroku & Glitch & Azure :up: :free: - GitHub - jesperorb/json-server-heroku: Deploy json-server to Heroku & Glitch & Azure
github.com
https://heeyeonjeong.tistory.com/102
Heroku로 react 프로젝트 배포하기 (json-server 포함)
json-server가 프로덕션 전용이 아닌 것을 알지만, 백엔드 서버가 없기 때문에.. 프로젝트 배포 시 json-server도 같이 배포하기 위해 여러 배포 서비스를 찾아봤다. 그전에 가장 쉽게 접근 가능한 gh-pag
heeyeonjeong.tistory.com