build - deploy ์ ๊ณผ์ ์ ๊ฑฐ์ณ์ ๋ฐฐํฌ๋ฅผ ํ๋ค.
Netlify ๋ฅผ์ด์ฉํด GitHub๊ณผ ์ฐ๋ํด์ ๋ฐฐํฌํ ์ ์๋ค.
master branch๋ก push๋ ๊ฒ๋ค์ ๊ฐ์ ธ์์ build, deploy ํด์ค๋ค. pushํ ๋๋ง๋ค build, deploy ํด์ค.๊ธฐ๋ณธ build ๋ช
๋ น์ด์ธ yarn build๊ฐ ์คํ๋๋ฉด build ๋๋ ํ ๋ฆฌ๊ฐ ์์ฑ๋๋ค.
...
7:29:32 PM: Post processing - HTML
7:29:32 PM: Post processing - header rules
7:29:32 PM: Post processing - redirect rules
7:29:32 PM: Post processing done
7:29:32 PM: Site is live
Deploy log์ Site is live ๋ผ๋ ๋ฌธ๊ตฌ๊ฐ ๋จ๋ฉด ์ฑ๊ณต์ ์ผ๋ก ๋ฐฐํฌํ ๊ฒ์ด๋ค.
๋! Front-end ๋ ์ฝ๋ค!
ํ ์ผ ์์ฝ
src ๋๋ ํ ๋ฆฌ์ ์์)์ babel์ ์ด์ฉํด ์ปดํ์ผ ํด์ build๋๋ ํ ๋ฆฌ์ ๋ฃ๊ธฐ.babel์ src ํด๋์ ์๋ graphql ํ์ผ์ ์ ๊ฒฝ์ฐ์ง ์๊ธฐ ๋๋ฌธ์ ๋ฐ๋ก ๋ณต์ฌํด์ฃผ๋ ๋ช
๋ น์ด ์์ฑ..gitignore์ ์๋ generated ํด๋์ prisma.yml ๋๋ฌธ์ Heroku์์ ๋ฐฐํฌํ ๋ ๋๋ ์๋ฌ ์ฒ๋ฆฌHeroku๋ฅผ ์ฌ์ฉํด์ ๋ฐฐํฌํ๋ค.
์ด ๋๊น์ง ์ด ์ฝ๋๋ค์ babel์ ์ด์ฉํด ์ปดํ์ผ ํด์ค์ผ ํ๋ค. pacakge.json์ scripts์ build๋ผ๋ ๋ช
๋ น์ด๋ฅผ ์ถ๊ฐํ์.
"scripts": {
...
"build": "babel src -d build"
}
$ yarn add @babel/cli
...
$ yarn build
src์ ์๋ ์ฝ๋๋ค์ build๋ผ๋ ํด๋์ ์ปดํ์ผํด์ ๋ฃ์ด์ค๋ค.
ํ์ํ ํ๋ฌ๊ทธ์ธ๋ค์ ์ค์นํ์.
$ yarn add @babel/plugin-transtorm-runtime -D
$ yarn add @babel/runtime
.babelrc
{
...
"plugins": ["@babel/plugin-transform-runtime"]
}
babel์ jsํ์ผ๋ง ๋ค๋ฃจ๊ธฐ ๋๋ฌธ์ graphqlํ์ผ์ ๋ณ๋๋ก buildํด๋์ ๋ฃ์ด์ค์ผ ํ๋ค.
๊ทธ๋์ copy ๋ชจ๋์ ์ฌ์ฉํ๋ค.
$ yarn add copy
"scripts": {
...
"build": "babel src -d build",
"postbuild": "cd src && npx copy \"api/**/*.graphql\" \"../build/api/\"",
}
์๋ฒ๋ฅผ ์์ํ๋ ์ฝ๋๋ ์ถ๊ฐํ์.
"scripts": {
...
"build": "babel src -d build",
"postbuild": "cd src && npx copy \"api/**/*.graphql\" \"../build/api/\"",
"start": "node build/server.js"
}
์ด์ Heroku๋ฅผ ์ด์ฉํด ๋ฐฐํฌํด๋ณด์.
New - Create new app์ ํตํด ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋ง๋ค์ด ์ฃผ๊ณ , heroku CLI๋ฅผ ์ค์นํด์ ์ฌ์ฉํ ๊ฒ์ด๋ค.
$ npm install -g heroku
์ค์นํ์ธ์:
$ heroku --version
์ค์น๋ฅผ ํ๋ค๋ฉด CLI์์ ๋ก๊ทธ์ธ์ ํด์ค๋ค
$ heroku login
์ด๋ฏธ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค ๋ Git repo๋ฅผ ๋ง๋ค์ด ๋จ๊ธฐ ๋๋ฌธ์ git init์ ์ ํด์ค๋ ๋๋ค.
$ heroku git:remote -a pack-easy-backend
$ git push heroku master
push๋ฅผ ํตํด refresh๋ฅผ ํ ์ ์๋ค.(Netlify์ฒ๋ผ)
app์ ์ด์ด์ฃผ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ค. ์ด์ ๋ generated๋ฅผ repo์ ์
๋ก๋ํ์ง ์์๊ธฐ ๋๋ฌธ์ด๋ค. (.gitignore)
Heroku๋ Git๊ณผ ์ฐ๋๋๊ธฐ ๋๋ฌธ์ Heroku์ ๋ญ๊ฐ ์ฌ๋ฆฌ๋ ค๋ฉด push๋ฅผ ํตํด ์ฌ๋ ค์ผ ํ๋๋ฐ, .gitignore์ด ํ์ผ๋ค์ ๋ฌด์ํด์ GitHub repo์ ์์ผ๋๊น ์ค๋ฅ๊ฐ ๋จ๋ ๊ฑฐ๋ค.
์ฆ, generated ํด๋๋ฅผ ์
๋ก๋ ํ์ง ์์๊ธฐ ๋๋ฌธ์, ์๋ฒ์ prisma client๋ฅผ ๋ฐ๋ก ์ค์นํด์ค์ผ ํ๋ค.
"scripts": {
...
"prebuild": "yarn run deploy && yarn run generate" // prisma client๋ฅผ ๋ฐ๋ก ์ค์นํด์ฃผ๋ ๊ณผ์
"build": "babel src -d build",
"postbuild": "cd src && npx copy \"api/**/*.graphql\" \"../build/api/\"",
"start": "node build/server.js"
}
๋์ ์ฝ๋์ ๊ฒฝ์ฐ์๋ prisma.yml ํ์ผ๋ .gitignoreํ์ผ์ ์๋ค. ์ฆ git์ ์
๋ก๋๋์ง ์๊ธฐ ๋๋ฌธ์ Heroku์์๋ ์ธ์ํ ์ ์๋ค.
๊ทธ๋์ prisma.yml์ ์๋ ๋ฏผ๊ฐํ ์ ๋ณด(endpoint url)๋ฅผ ํ๊ฒฝ๋ณ์๋ก ๋๊ณ , ๊ทธ ํ๊ฒฝ๋ณ์๋ฅผ ์ฐธ์กฐํ๋ ์์ผ๋ก ์ฝ๋๋ก ๋ฐ๊พธ๊ณ , .gitignore์์ ์ง์์คฌ๋ค. ํ๊ฒฝ๋ณ์๋ Heroku ์ค์ ์์ ํ ์ ์๋ค.
"scripts": {
...
"prebuild": "yarn run deploy && yarn run generate",
"build": "babel src -d build",
"postbuild": "cd src && npx copy \"api/**/*.graphql\" \"../build/api/\"",
"start": "node build/server.js"
}
๋ด๊ฐ ๋ฐ๊พผ ์ฝ๋๋ฅผ Heroku์ ๋ฐ์ํ๋ ค๋ฉด git push heroku master์ ํด์ค์ผ ํ๋ค.
pushํ๊ธฐ ์ ์ ๋งค๋ฒ commit ๋ฉ์์ง๋ฅผ ๋จ๊ธฐ๊ธฐ ์ซ๋ค๋ฉด git commit --amend --no-edit์ ํ๋ฉด ๋๋ค.
๋ง์ง๋ง์ผ๋ก git push heroku master์ ํด์ฃผ๋ฉด
remote: -----> Compressing...
remote: Done: 64.5M
remote: -----> Launching...
remote: Released v11
remote: https://๐ค.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To https://git.heroku.com/๐ค.git
9f1b4cb..c029b42 master -> master
deploy๋ ์ฃผ์๋ฅผ ์ ์ ์๋ค.

graphql playground๊ฐ ์๊ณ docs๋ฅผ ๋ณด๋ฉด ๋ด๊ฐ ์ง๋จ๋ API๋ค์ด ์ ์ ์ฉ๋๋ค!
์ด์ ๊ฐ๋ฐ๋จ๊ณ์์ ์ฌ์ฉํ๋ prisma demo ์๋ฒ ๋ง๊ณ , ์ ๋๋ก ๋ ์๋ฒ๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
app.prisma.io๋ก ๊ฐ์ ์ Workspace๋ฅผ ๋ง๋ค๊ณ , ์๋ฒ๋ฅผ ์ถ๊ฐํ๊ณ , ์๋น์ค๋ฅผ ์ถ๊ฐํ๋ฉด ๋๋ค.
์๋ฒ๋ฅผ ์๋ก ๋ง๋ค ๋ DB๋ฅผ ์๋ ์๋ ๊ฑธ ์ฌ์ฉํ ์ง, ์๋ก ๋ง๋ค์ง ์ ํํ๋๋ฐ ์๋ก ๋ง๋ค๊ฒ ๋๋ฉด DB๋ฅผ ํธ์คํ ํด์ค provider๊ฐ Heroku๋ค. ๊ทธ๋์ back-end deploy๋ Heroku๋ฅผ ์ด์ฉํด์ ํ๊ฑฐ๋ค.
์๋ฒ๋ฅผ ๋ง๋ค์์ผ๋ฉด ์ด์ ์๋น์ค๋ฅผ ์ถ๊ฐํด์ค์ผ ํ๋ค. ์๋น์ค๋ฅผ ์ถ๊ฐํ๋ ค๋ฉด Prisma CLI์ ๋ก๊ทธ์ธ ํด์ผ ํ๋ค.
$ prisma login -k <๋ฐ๊ธ๋ ํค>
์๋น์ค๋ฅผ ์ถ๊ฐํด์ฃผ๊ณ
https://<server-endpoint>/<service-name>/<stage>
๋ฅผ prisma.yml์ endpoint์ ๋ฃ์ด์ฃผ๊ณ
$ prisma deploy
๋ฅผ ํด์ฃผ๋ฉด ๋ณ๊ฒฝ์ฌํญ์ด ๋ฐ์๋์ด ์๋น์ค๊ฐ ์ ๋ฐ์ดํธ๋๋ค.
deploy๋ ๋๋ฌ๋ค. ์ด์ ์ ๊ฐ๋ฐ ๋จ๊ณ์์ ์ค์ ํด๋จ๋ ์ค์ ๋ค ์ค์ ๋ฐ๊ฟ์ค์ผ ํ ๊ฒ๋ง ๋ฐ๊ฟ๋ณด์.
Frontend
ApolloClient ๊ด๋ จํ ์ค์ :
export default new ApolloClient({
uri: process.env.NODE_ENV === "development" ? 'http://localhost:4000' : "https://๐ค.herokuapp.com/",
clientState: {
defaults,
resolvers
}
});
DEV ์ผ ๋๋ ๋ฐฑ์๋ ์ฃผ์๋ฅผ localhost:4000์ผ๋ก ํ๊ณ ์๋ ๋๋ deployํ๋ ์ฃผ์๋ก ์ง์ ํด์ค๋ค.
Backend
prisma.yml์ endpoint ์ฃผ์๋ ์๊น Heroku์ ํ๊ฒฝ๋ณ์๋ก ์ถ๊ฐํด์คฌ๊ธฐ ๋๋ฌธ์ ํ๊ฒฝ๋ณ์๋ฅผ ์ฐธ์กฐํ๊ฒ ๋ฐ๊พผ๋ค.
endpoint: ${env:PRISMA_ENDPOINT}
์ฒ์์๋ ๋ด ์ค์ ํ์ผ .env์ ํ๊ฒฝ๋ณ์๊ฐ์ ๋ฃ์ด๋จ๋๋ฐ Heroku๊ฐ ์ฐพ์ง๋ฅผ ๋ชปํ๋ค. ์ด ๊ฒ๋ GitHub repo์ ์ ์ฌ๋ผ๊ฐ๊ธฐ ๋๋ฌธ์ด๋ค.
๋ง์ง๋ง์ผ๋ก generated ํด๋์ index.js์ prisma client์ endpoint ์ฃผ์๊ฐ ์๋ ์ฐ๋ demo ์๋ฒ์ ์ฃผ์๋ก ๋์ด ์๋ค. ์ด ๊ฒ๋ ์ด ํ์ผ์ ๋ฐ๊พผ๋ค๊ณ ํด์ GitHub repo์ ์ฌ๋ผ๊ฐ๋ ๊ฒ ์๋๊ธฐ ๋๋ฌธ์ Heroku์์ ๋ฐ์ํ์ง ๋ชปํ๋ค. ๊ทธ๋์ ์์ rebuild๋ฅผ ํด์ ์
๋ฐ์ดํธํ๊ฒ๋ ํด์ผ ํ๋ค.
$ git commit --allow-empty -m "Nothing" // empty commit
$ git push heroku master
ํด์ฃผ๋ฉด rebuild๋ฅผ ํ๋ฉด์ prisma generate๋ฅผ ํ๊ธฐ ๋๋ฌธ์ ์๊น ๋ก๊ทธ์ธ ํ๋ ์๋ฒ์ ์๋น์ค๋ฅผ ๋์์ผ๋ก prisma client๋ฅผ ์๋ก ๋ง๋ค์ด์ฃผ๊ณ , endpoint๋ ์
๋ฐ์ดํธ๋๋ค.
Netlify์์ ๋ฐฐํฌํ ์ฌ์ดํธ๋ก ๊ฐ๋ณด๋ฉด ์ ์๋ํ๊ณ , ์ฟผ๋ฆฌ๋ฅผ ๋ณด๋ด๋ณด๋ฉด ์๋ฒ๋ ์ ์๋ํ๊ณ prisma๊ฐ DB์๋ ์์ฒญ์ ์ฃผ๊ณ ๋ฐ๋ ๊ฒ์ ํ์ธํ ์ ์๋ค!!
์ด Deployํ ๊ฒ์ด Front-end, Back-end, Prisma server ์ด ์ธ ๊ฐ์๋ค.
git.heroku.com์ repo๊ฐ ๋ง๋ค์ด์ ธ ๊ฑฐ๊ธฐ์ ์ฐ๋๋๋ค๋ ๊ฒ์ด๋ค.git push heroku master๋ฅผ ํตํด ์์ repo๋ก ๋ณด๋ด์ค์ผ ํ๋ค.app.primsa.io๋ก ๊ฐ๋ณด๋ฉด ์๋ก์ด ์๋ฒ๋ฅผ ๋ง๋ค ๋, Heroku๋ฅผ DB provider๋ก ์ฌ์ฉํ๋ค. Back-end๋ฅผ ๋ฐฐํฌํ ๋ Heroku๋ฅผ ์ฌ์ฉํ ์ด์ ๋ ์ด ๋๋ฌธ์ด๋ค. ์๋ฒ๋ฅผ ํธ์คํ
ํ๊ณ , ๊ทธ ์์ ์๋น์ค๋ฅผ ์๋ก ๋ง๋ ๋ค, ์ฐ๋ฆฌ๊ฐ ๋ง๋ค์ด๋จ๋ ๋๋ ํ ๋ฆฌ์์ ์๋ก prisma client๋ฅผ ์์ฑํด์ฃผ๋ฉด ์๋ฒ์ธก์์ DB์ prisma client์์ ์ ๊ณตํ๋ API๋ฅผ ์ด์ฉํด ์์ฒญ / ์๋ตํ๋ค.๊ผฌ๋ฐ ํ๋ฃจ๋ฅผ ์จ์ ๋ฐฐํฌ์ ์ฑ๊ณตํ๋ค.. Back-end๋ฅผ ๋ฐฐํฌํ ๋ ์ด๋ ค์์ ๊ฒช์์ง๋ง ๋๋จธ์ง๋ ์๋ ์ ๋์ด์์ด์ ๋๋ฆ ๊ด์ฐฎ์๋ค. ๊ทธ๋๋ ํ๋ฒ ํด๋๊ณ ๋๋๊น ๋ค์์๋ ๊ฑ ํ ์ ์์ ๊ฒ ๊ฐ๋ค.
๐ถ๐ถ will help you : )
๐ Prisma DOCS
https://v1.prisma.io/docs/1.34/get-started/01-setting-up-prisma-demo-server-JAVASCRIPT-a001/
๐ Heroku DOCS
https://devcenter.heroku.com/articles/git
๐ Netlify DOCS
https://docs.netlify.com/site-deploys/create-deploys/#deploy-with-git