Skip to content

ParkYoungWoong/todo_vite-vue3-composition-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

13 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“Œ ํ•  ์ผ(Todo) ๊ด€๋ฆฌ ์•ฑ

์ฃผ์–ด์ง„ API๋ฅผ ํ™œ์šฉํ•ด '์™„์„ฑ ์˜ˆ์‹œ' ์ฒ˜๋Ÿผ ํ•  ์ผ(Todo) ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.
Vue Composition API + TypeScript๋ฅผ ์‚ฌ์šฉํ•ด ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค.

์™„์„ฑ ์˜ˆ์‹œ
์™„์„ฑ ์˜ˆ์‹œ

Vue Options vs Composition

  • Options API: ๊ฐ•์ œํ•˜๋Š” ์˜ต์…˜ ์‚ฌ์šฉ์œผ๋กœ ๋‚ฎ์€ ์ง„์ž… ์žฅ๋ฒฝ ์ œ๊ณต, ๊ธฐ์กด ์ฝ”๋“œ(>=@2)์™€ ํ˜ธํ™˜์„ฑ ์œ ์ง€
  • Composition API: ์œ ์—ฐํ•œ ๊ตฌ์กฐ๋กœ ์ฝ”๋“œ ์žฌ์‚ฌ์šฉ์„ฑ ํ–ฅ์ƒ ๊ฐ€๋Šฅ, ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ ํ˜ธํ™˜์„ฑ ํ–ฅ์ƒ

Pinia

https://pinia.vuejs.org/

  • Vue.js ํ•ต์‹ฌ ํŒ€ ๋ฉค๋ฒ„๊ฐ€ ๊ฐœ๋ฐœํ•œ ์ƒํƒœ ๊ด€๋ฆฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ
  • ๊ณต์‹ Vuex์™€ ์œ ์‚ฌํ•˜์ง€๋งŒ, ๋” ๊ฐ„๋‹จํ•˜๊ณ  ์ง๊ด€์ ์ธ API ์ œ๊ณต
  • Vue.js ์ธก์—์„œ ๊ณต์‹์ ์œผ๋กœ ์‚ฌ์šฉ์„ ์ถ”์ฒœ
  • ๋‹ค์Œ ๋ฒ„์ „์˜ ๊ณต์‹ Vuex์—์„œ ์ฐจ์šฉํ•˜๊ฑฐ๋‚˜ ์•„์˜ˆ Pinia๋กœ ์ „ํ™˜ ์˜ˆ์ •

Vercel

Vercel SPA Fallback

Vue Router์˜ HTML5 ๋ชจ๋“œ์—์„œ ๋‹จ์ผ ํŽ˜์ด์ง€ ์•ฑ(SPA)์„ ์ œ๊ณตํ•  ๋•Œ๋Š” ์ ์ ˆํ•œ ์„œ๋ฒ„ ๊ตฌ์„ฑ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.
์šฐ๋ฆฌ๋Š” Vercel ํ˜ธ์ŠคํŒ…์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ, ๋ชจ๋“  ๊ฒฝ๋กœ์— ๋Œ€ํ•ด index.html ํŒŒ์ผ์„ ์ œ๊ณตํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์˜ต์…˜์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

https://vercel.com/docs/concepts/projects/project-configuration#legacy-spa-fallback

/ vercel.json

{
  "routes": [
    { "handle": "filesystem" },
    { "src": "/(.*)", "dest": "/index.html" }
  ]
}

Vercel ๋‚ด๋ถ€ ์ข…์†์„ฑ ๋ฒ„์ „ ์žฌ์ •์˜

ํƒ€์ž…์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ์ง์ ‘ ์„ค์น˜ํ•œ ๋ฒ„์ „๊ณผ Vercel(@vercel/node) ๋‚ด๋ถ€์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฒ„์ „์ด ๋‹ค๋ฅธ ๊ฒฝ์šฐ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ผ์น˜์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
Vercel ์„œ๋ฒ„๋ฆฌ์Šค ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ, ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

/package.json

{
  "devDependencies": {
    "typescript": "^5.0.2",
    "vercel": "^30.2.1"
  },
  "overrides": {
    "@vercel/node": {
      "ts-node": "10.9.1",
      "typescript": "5.0.2"
    }
  }
}

ESLint

/.eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:vue/vue3-recommended",
    "plugin:prettier/recommended"
  ],
  "parserOptions": {
    "parser": "@typescript-eslint/parser"
  }
}
  • parser: ESLint ์ „๋ฐ˜์— ๊ฑธ์ณ ์‚ฌ์šฉํ•˜๋Š” ๊ธฐ๋ณธ ํŒŒ์„œ๋ฅผ ์„ค์ •
  • parserOptions.parser: ํŠน์ • ํ”Œ๋Ÿฌ๊ทธ์ธ(Vue)์—์„œ ์‚ฌ์šฉํ•˜๋Š” ํŒŒ์„œ๋ฅผ ์„ค์ •

API ์ •๋ณด

๋ชจ๋“  ์š”์ฒญ์€ ๋‹ค์Œ Headers ์ •๋ณด๊ฐ€ ํ•„์ˆ˜๋กœ ํฌํ•จ๋ผ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
<APIKEY>์™€ <USERNAME> ์ •๋ณด๋Š” ๋ณ„๋„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

curl <ENDPOINT>
  \ -X <METHOD>
  \ -H 'content-type: application/json'
  \ -H 'apikey: <APIKEY>'
  \ -H 'username: <USERNAME>'

ํ•  ์ผ ๋ชฉ๋ก ์กฐํšŒ

์ „์ฒด ํ•  ์ผ ๋ชฉ๋ก์„ ์กฐํšŒํ•ฉ๋‹ˆ๋‹ค.

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos
  \ -X 'GET'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

  • N/A

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

type ResponseValue = Todo[] // ํ•  ์ผ ๋ชฉ๋ก

interface Todo {
  id: string // ํ•  ์ผ ID
  order: number // ํ•  ์ผ ์ˆœ์„œ
  title: string // ํ•  ์ผ ์ œ๋ชฉ
  done: boolean // ํ•  ์ผ ์™„๋ฃŒ ์—ฌ๋ถ€
  createdAt: string // ํ•  ์ผ ์ƒ์„ฑ์ผ
  updatedAt: string // ํ•  ์ผ ์ˆ˜์ •์ผ
}
[
  {
    "id": "mnIwaAPIAE1ayQmqekiR",
    "order": 0,
    "title": "JS ๊ณต๋ถ€ํ•˜๊ธฐ",
    "done": false,
    "createdAt": "2021-10-28T05:18:51.868Z",
    "updatedAt": "2021-10-28T05:18:51.868Z"
  },
  {
    "id": "tMzPImGoWtRdJ6yyVv2y",
    "order": 1,
    "title": "๊ณผ์ œ PullRequest(PR) ์ƒ์„ฑ",
    "done": true,
    "createdAt": "2021-10-28T04:16:53.980Z",
    "updatedAt": "2021-10-28T09:40:17.955Z"
  },
  {
    "id": "Rq8BebKihCgteHHhMIRS",
    "order": 2,
    "title": "API ์Šคํ„ฐ๋””",
    "done": false,
    "createdAt": "2021-10-28T04:17:02.510Z",
    "updatedAt": "2021-10-28T04:17:02.510Z"
  }
]

ํ•  ์ผ ํ•ญ๋ชฉ ์ถ”๊ฐ€

ํ•  ์ผ ํ•ญ๋ชฉ์„ ์ƒˆ๋กญ๊ฒŒ ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค.

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos
  \ -X 'POST'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface RequestBody {
  title: string // ํ•  ์ผ ์ œ๋ชฉ
  order?: number // ํ•  ์ผ ์ˆœ์„œ
}
{
  "title": "KDT ๊ณผ์ • ์„ค๊ณ„ ๋ฏธํŒ…"
}

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface ResponseValue {
  id: string
  order: number
  title: string
  done: boolean
  createdAt: string
  updatedAt: string
}
{
  "id": "7P8dOM4voAv8a8cfoeKZ",
  "order": 0,
  "title": "KDT ๊ณผ์ • ์„ค๊ณ„ ๋ฏธํŒ…",
  "done": false,
  "createdAt": "2021-10-29T07:20:02.749Z",
  "updatedAt": "2021-10-29T07:20:02.749Z"
}

ํ•  ์ผ ํ•ญ๋ชฉ ์ˆ˜์ •

ํŠน์ • ํ•  ์ผ ํ•ญ๋ชฉ์„ ์ˆ˜์ •ํ•ฉ๋‹ˆ๋‹ค.

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/:todoId
  \ -X 'PUT'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface RequestBody {
  title: string // ํ•  ์ผ ์ œ๋ชฉ
  done: boolean // ํ•  ์ผ ์™„๋ฃŒ ์—ฌ๋ถ€
  order?: number // ํ•  ์ผ ์ˆœ์„œ
}
{
  "title": "Bootstrap ์Šคํƒ€์ผ ์ถ”๊ฐ€",
  "done": false
}

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface ResponseValue {
  id: string
  order: number
  title: string
  done: boolean
  createdAt: string
  updatedAt: string
}
{
  "id": "7P8dOM4voAv8a8cfoeKZ",
  "title": "Bootstrap ์Šคํƒ€์ผ ์ถ”๊ฐ€",
  "done": false,
  "order": 2,
  "createdAt": "2021-10-29T07:20:02.749Z",
  "updatedAt": "2021-10-29T07:20:02.749Z"
}

ํ•  ์ผ ํ•ญ๋ชฉ ์‚ญ์ œ

ํŠน์ • ํ•  ์ผ ํ•ญ๋ชฉ์„ ์‚ญ์ œํ•ฉ๋‹ˆ๋‹ค.

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/:todoId
  \ -X 'DELETE'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

  • N/A

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

type ResponseValue = true // ์ •์ƒ ์‘๋‹ต

ํ•  ์ผ ํ•ญ๋ชฉ ์ผ๊ด„ ์‚ญ์ œ

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/deletions
  \ -X 'DELETE'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface RequestBody {
  todoIds: string[] // ์‚ญ์ œํ•  ํ•  ์ผ ID ๋ชฉ๋ก
}
{
  "todoIds": [
    "mnIwaAPIAE1ayQmqekiR",
    "tMzPImGoWtRdJ6yyVv2y",
    "GHrvr3LaPx1g7y2sNuaC",
    "Rq8BebKihCgteHHhMIRS"
  ]
}

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

type ResponseValue = true // ์ •์ƒ ์‘๋‹ต

ํ•  ์ผ ๋ชฉ๋ก ์ˆœ์„œ ๋ณ€๊ฒฝ

ํ•  ์ผ ๋ชฉ๋ก์˜ ์ˆœ์„œ๋ฅผ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค.

curl https://asia-northeast3-heropy-api.cloudfunctions.net/api/todos/reorder
  \ -X 'PUT'

์š”์ฒญ ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

interface RequestBody {
  todoIds: string[] // ์ƒˆ๋กญ๊ฒŒ ์ •๋ ฌํ•  ํ•  ์ผ ID ๋ชฉ๋ก
}
{
  "todoIds": [
    "mnIwaAPIAE1ayQmqekiR",
    "tMzPImGoWtRdJ6yyVv2y",
    "GHrvr3LaPx1g7y2sNuaC",
    "Rq8BebKihCgteHHhMIRS"
  ]
}

์‘๋‹ต ๋ฐ์ดํ„ฐ ํƒ€์ž… ๋ฐ ์˜ˆ์‹œ:

type ResponseValue = true // ์ •์ƒ ์‘๋‹ต