๐ฆ ํ์ด ํ๋ ๊ธฐ๋ก_Day8 - boostcampwm-2022/web33-Mildo GitHub Wiki
1. Aํ(ํ๋น, ์์ค)
1.1. ์ด์ ๋ถ๋ฐฐ
- ๋ค์ด๋ฒ ์ง๋ API ์ฐ๊ฒฐ
- ์ง๋ ์ด๊ธฐ ํ๋ฉด์ ์์ธ ์ค์ฌ์ผ๋ก ์ถ๋ ฅ
1.2. ๊ตฌํ ๋ชฉํ
- ์ฌ์ฉ์๊ฐ ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์ ๋ค์ด๋ฒ ์ง๋ ํ๋ฉด์ ํ์ธํ ์ ์์ด์ผ ํจ
- ๊ธฐ์กด ์ด์๋ฅผ ์ ์ ํ๊ฒ ๋๋ ์ ์ธ๋ถ ๋ชฉํ ์์ฑ
- branch name : feature/map
1.3 ์ธ๋ถ ๋ชฉํ
1.3.1. Mildo์ ๋ค์ด๋ฒ ์ง๋ API ๊ฐ์ ธ์์ ๋ณด์ฌ์ฃผ๊ธฐ
- ๋ค์ด๋ฒ ์ง๋ API ์ฌ์ฉ๋ฒ ์ตํ๊ธฐ
- nCloud์์ API ์ด์ฉ ์ ์ฒญํ๊ณ ํ๋ก์ ํธ url ์ถ๊ฐ
- ํ๋น์ด ์ด์ ์ ์ฌ์ฉํ ์๋น์ค๋ฅผ ์ ์ฉํ์๊ณ , ํ์ฌ url์ localhost
- Web Dynamic Map ์ฌ์ฉ
- Application Key์์ Client ID ๊ฐ์ ธ์ค๊ธฐ
- url๊ณผ Client ID๋ฅผ ์ฌ์ฉํ์ฌ ํ๋ก์ ํธ์ API ์ฐ๊ฒฐํ๊ธฐ
- public/index.html์ head์ script ํ๊ทธ์ src ์์ฑ์ ํด๋น ๋ด์ฉ ์ถ๊ฐ
- typescript ํ์ ์ค์ ์ ์ํ @types/navermaps ์ค์น
- ๋งต ๊ด๋ จ ์ปดํฌ๋ํธ ์์ฑ
- ๋งต์ ๊ทธ๋ฆด DOM ์์ ์์ฑ
- map ์ต์ ์ค์ ํ๊ธฐ(์์น, ์ค ๋ฑ)
- DOM์ ๋ค์ด๋ฒ ์ง๋ ๊ทธ๋ ค์ฃผ๊ธฐ
- ์ปดํฌ๋ํธ ๋ ๋๋ง ํ์ธ
- ์ฐธ๊ณ ์๋ฃ
1.4. ์์ฌ๊ฒฐ์
1.4.1. ๋ชจ๋ฐ์ผ ํ๊ฒฝ์์ ์ง๋ ๋ฉ์ธ ํ๋ฉด ๊ตฌ์ฑ
- Map ์ปดํฌ๋ํธ๋ฅผ ์์ฑํ๊ณ MainPage๋ ๋ณ๋๋ก ์์ฑ?
- Map ๊ด๋ จ ๋ก์ง์ด ๋ฐ๋ก ์๋์ง?
- ๋ฉ์ธ ํ๋ฉด ๊ตฌ์ฑ์ด ์ง๋ ์์
์ ํฌํจ๋๋๊ฐ?
- ๋ฉ์ธ ํ๋ฉด : ์ง๋๋ฅผ ๋์ด์ฃผ๊ณ , ๊ทธ ํฌ๊ธฐ๋ฅผ ๋ชจ๋ฐ์ผ UI์ ๋ง๊ฒ ์ค์ (O)
- ๋ฉ์ธ ํ๋ฉด์ ๊ตฌ์ฑ ์์ : ๊ฒ์๋ฐ, ํํฐ ๋ฑ๋ฑ (X)
1.4.2. ์๋ ผ ์ฌํญ
- mainPage๋ฅผ ๋ณ๋๋ก ๋ง๋ค์ด์ผ ํ ๊น?
- ์ด์ฐจํผ spa ๊ตฌํ์ด๋๊น Map ์ปดํฌ๋ํธ๋ฅผ mainPage์ฒ๋ผ ์ฌ์ฉ?
- ํ์ฅ์ฑ ๊ณ ๋ คํด์ Map, ๊ฒ์๋ฐ, ํํฐ ๋ฑ์ ์ปดํฌ๋ํธ๋ก ์ ์ํ๊ณ mainPage๋ฅผ ๋ณ๋๋ก ๊ตฌ์ฑ?
- ์ฐ์ Aํ์์ 2๋ฒ์งธ ์์ผ๋ก ์ ์ ๊ฒฐ์
- ๋ชจ๋ฌ์ด ์ปดํฌ๋ํธ์ธ๊ฐ? โ ๋ชจ๋ฌ์ ๋ ์ด์์(Wrapper)๊ณผ ๋ชจ๋ฌ์ ๋ด์ฉ๋ฌผ์ ์๋ก ๋ถ๋ฆฌํ์!
- ๋ชจ๋ฌ์ ๋ด๋ถ์ ์ปดํฌ๋ํธ๊ฐ ๋ ๋ค์ด๊ฐ๋ ์ํฉ์ด๋ฉด, ๋ชจ๋ฌ ์์ฒด๋ฅผ ์ปดํฌ๋ํธ๋ผ๊ณ ๋ณผ ์ ์๋?
- components, pages, modals๊ฐ ๋ค ๋ณ๋๋ก ์กด์ฌ?
- ๋ชจ๋ฌ์ ๋ด๋ถ์ ์ปดํฌ๋ํธ๊ฐ ๋ ๋ค์ด๊ฐ๋ ์ํฉ์ด๋ฉด, ๋ชจ๋ฌ ์์ฒด๋ฅผ ์ปดํฌ๋ํธ๋ผ๊ณ ๋ณผ ์ ์๋?
- Geocoding(์ค์๋ : ํ)
- ์ฃผ์์ ํ ์คํธ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ์ขํ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์
- ๊ฒ์ ๊ธฐ๋ฅ์์ ์ฌ์ฉํ ์ ์์ง ์์๊น?
2. Bํ(ํ์ , ์ค์ฐ)
2.1. ์ด์ ๋ถ๋ฐฐ
- express ์๋ฒ ์ฐ๊ฒฐ
- ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API ์ฐ๊ฒฐ
- ์ฃผ์ ์ฅ์ 50๊ณณ์ ๋ํ ์ธ๊ตฌ๋ฐ๋/์๋/๊ฒฝ๋ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
2.2. ๊ตฌํ ๋ชฉํ
- ๋ฐฑ์๋์์ ์์ธ ์ค์๊ฐ ๋์๋ฐ์ดํฐ๋ฅผ ๊ฐ์ ธ์ฌ ์ ์๋ค.
- branch name : feature/connect-seoul-api
2.3. ํ ์ผ
- express ์๋ฒ ์ฐ๊ฒฐ
- ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API ์ฐ๊ฒฐ
- ์ฃผ์ ์ฅ์ 50๊ณณ์ ๋ํ ์ธ๊ตฌ๋ฐ๋, ์ฅ์ ์ ๋ณด ๊ฐ์ ธ์ค๊ธฐ
- ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ ์ฅ์, ์ธ๊ตฌ๋ฐ๋, ์๋/๊ฒฝ๋X
- ๋ค์ด๋ฒ geocoding api ์๋/๊ฒฝ๋
- github secrets์๋ค ๋ฐฐํฌ์ ํ์ํ ํ๊ฒฝ๋ณ์ ์ ์
2.4. ์์ฌ๊ฒฐ์
2.4.1. xml2js
- ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API์์๋ xml ํ์์ผ๋ก๋ง ์๋ต์ ๋ฐ์์ฌ ์ ์์
- ๊ณต์ ์ฌ์ดํธ์ json ํ์์ผ๋ก ๋ฐ์์ฌ ์ ์๋ค๊ณ ๋์์์ด ์๋ํด๋ดค์ง๋ง xml ํ์๋ง ์ง์ํ๋ค๊ณ ์๋ต
- ํ์ฑ์ด ์ฃผ๋ ๋ชฉํ๊ฐ ์๋์๊ณ , ๋น ๋ฅด๊ฒ ํ์ฑํ๊ธฐ ์ํด
xml2js
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํด์ xmlํ์ผ์ json ํ์์ผ๋ก ํ์ฑ
2.5. ๊ตฌํ ๋ด์ฉ
2.5.1. ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ ์ฃผ์ 50๊ณณ ์๋ต ํ์ธ
- ์์ธ ์ฃผ์ 50๊ณณ์ ๋ฐ์ดํฐ๋ฅผ ํ๋ฒ์ ๊ฐ์ ธ์ค๋ api ์์ฒญ์ด ์๊ธฐ ๋๋ฌธ์ 50๊ณณ ๊ฐ๊ฐ์ ๋ํด ์์ฒญ์ ํด์ผ๋จ
- ์์ธ ์ฃผ์ 50๊ณณ์ ๋ํด ์์๋ก ๋ชจ๋ ์์ฑ
- ์์ธ ์ฃผ์ 50๊ณณ์ ๋ํด api๊ฐ ์๋ต์ ๋ชจ๋ ํ๋์ง ํ์ธ
2.5.2. ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API ์๋ต ๊ฐ๊ณต
-
์์ธ ๋์ ๋ฐ์ดํฐ์ ์์ฒญ์ผ๋ก json์ด ์๋ xml๋ฐ์ ์๋ต๋ฐ์ ์ ์์ด xml2js ๋ชจ๋์ ์ค์นํ์ฌ ํ์ฑ
-
์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API ์๋ต์์ ํ์ํ ๋ฐ์ดํฐ๋ง ๊ฐ๊ณตํ์ฌ
res.send
ํจ -
๊ฒฐ๊ณผ
{ "ok": true, "data": [ { "areaName": [ "๊ฒฝ๋ณต๊ถยท์์ด๋ง์" ], "populationMin": [ "6000" ], "populationMax": [ "6500" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๊ดํ๋ฌธยท๋์๊ถ" ], "populationMin": [ "7500" ], "populationMax": [ "8000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "์ฐฝ๋๊ถยท์ข ๋ฌ" ], "populationMin": [ "5000" ], "populationMax": [ "5500" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๊ฐ๋จ MICE ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "2500" ], "populationMax": [ "3000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๋๋๋ฌธ ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "18000" ], "populationMax": [ "20000" ], "populationLevel": [ "๋ณดํต" ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๋ช ๋ ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "14000" ], "populationMax": [ "16000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "์ดํ์ ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "4500" ], "populationMax": [ "5000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "์ ์ค ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "22000" ], "populationMax": [ "24000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "์ข ๋กยท์ฒญ๊ณ ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "12000" ], "populationMax": [ "14000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "ํ๋ ๊ด๊ดํน๊ตฌ" ], "populationMin": [ "38000" ], "populationMax": [ "40000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๊ตญ๋ฆฝ์ค์๋ฐ๋ฌผ๊ดยท์ฉ์ฐ๊ฐ์กฑ๊ณต์" ], "populationMin": [ "400" ], "populationMax": [ "500" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๋จ์ฐ๊ณต์" ], "populationMin": [ "7500" ], "populationMax": [ "8000" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, { "areaName": [ "๋์ฌํ๊ฐ๊ณต์" ], "populationMin": [ "2000" ], "populationMax": [ "2500" ], "populationLevel": [ "์ฌ์ " ], "updatedAt": [ "2022-11-16 22:35" ] }, ... ... ... ... ] }
2.6. Trouble Shooting
2.6.1. ๊ฐ์ฒด ์ํ, ๋ฐฐ์ด ์ํ
for (const index in Array) {
console.log(index); // index ์ถ๋ ฅ
}
for (const value of Array) {
console.log(value); // value ์ถ๋ ฅ
}
for (const key in Object) {
console.log(key); // key๊ฐ ์ถ๋ ฅ
}
- ๋ฌธ์ ์ : ๋ฐฐ์ด์ ์ง์ญ ์ด๋ฆ(string)์ด ๋ค์ด๊ฐ์ผ ํ๋๋ฐ ์ซ์(number)๊ฐ push๋๋ ์ค๋ฅ ๋ฐ์
- ์์ธ : ๊ฐ์ฒด ์ํ, ๋ฐฐ์ด ์ํ๋ฅผ ์๋ชป๋ ๋ฐฉ๋ฒ์ผ๋ก ํ๊ณ ์์์
- ํด๊ฒฐ : 1๋ฒ ๋ฐฉ๋ฒ โ 3๋ฒ ๋ฐฉ๋ฒ์ผ๋ก ๋ณ๊ฒฝ
- 21, 33, 36, 39, 42๋ฅผ ์ ์ธํ ๋๋จธ์ง ์ซ์๋ค์ ์ฐ์ฐํ ๊ฐ๊ฐ ๋ด๋นํ๋ ์ง์ญ ์์ด๋๋ฅผ ๋ด๋นํ๊ณ ์์ด์ ์ ์์ ์ผ๋ก ์๋ตํจ
- 21, 33, 36, 39, 42๋ฅผ ๋ด๋นํ๋ ์ง์ญ์ ์์๊ธฐ ๋๋ฌธ์ ์์ธ ์ค์๊ฐ ๋์ ๋ฐ์ดํฐ API์์
INFO-200
์ฝ๋๋ก ์๋ตํจINFO-200
:ํด๋นํ๋ ๋ฐ์ดํฐ๊ฐ ์์ต๋๋ค.
2.7. ๋ด์ผ ํ ์ผ
-
res.send
โres.json
์ผ๋ก ๋ณ๊ฒฝ - ์๋ฒ ์ค๋ฅ ์ํ ์ฝ๋ ๋ ผ์
- ๋ค์ด๋ฒ geocoding api๋ฅผ ์ฌ์ฉํ ์ง ๋ ผ์(ํ ๋ฒ๋ง ๊ฐ์ ธ์ค๋ฉด ๋๊ธฐ ๋๋ฌธ์ ์์๋ก ์ฒ๋ฆฌํด๋ ๋ ๊ฒ ๊ฐ์)
- 50๊ณณ์ ๋ํด ๋๊ธฐ์ ์ผ๋ก ๋ง๊ณ ๋น๋๊ธฐ์ ์ผ๋ก ์ฒ๋ฆฌํด์ผ ๋ ๊ฒ ๊ฐ์,
promise.all