250x250
λ°˜μ‘ν˜•
Notice
Recent Posts
Recent Comments
Link
Β«   2024/12   Β»
일 μ›” ν™” 수 λͺ© 금 ν† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
Archives
Today
Total
관리 메뉴

BEAT A SHOTGUN

[ERROR] Set up a proxy and set up multiple proxies λ³Έλ¬Έ

TROUBLESHOOTING

[ERROR] Set up a proxy and set up multiple proxies

thovy 2022. 11. 11. 02:38
728x90
λ°˜μ‘ν˜•
SMALL

μ‹œμž‘πŸ‘Š

Set up

ν”„λ‘μ‹œ ν•˜λ‚˜λ₯Ό μ„€μ •ν•˜λŠ” 방법은 쉽닀.
ν”„λ‘μ‹œ μ—¬λŸ¬ κ°œλŠ” μ–΄λ–»κ²Œ ν•˜μ§€?

일단 ν”„λ‘μ‹œ ν•˜λ‚˜λŠ”

package.json 에
proxy:"λ³€κ²½ν•  μ£Όμ†Œ" λ₯Ό μ μ–΄λ„£μœΌλ©΄ λœλ‹€.
proxyμ„€μ •

λ§Œμ•½ proxy λ₯Ό μ•ˆ 적어 λ„£μœΌλ©΄ CORS μ—λŸ¬κ°€ λ°œμƒν•œλ‹€.

일단 넣어놓고 잘 λœλ‹€ μ‹Άμ—ˆλŠ”λ°...

μƒν™©πŸ€·‍♂️

λ¬Έμ œλŠ” λ‚΄κ°€ μš”μ²­μ„ λ³΄λ‚΄μ•Όν•˜λŠ” 곳이 μ—¬λŸ¬ κ°œλ‹€ 🀦‍♂️

ν•œκ΅­νˆ¬μžμ¦κΆŒμ˜ openapivts 와 κ³΅κ³΅λ°μ΄ν„°ν¬ν„Έμ˜ seibro 둜 각각 μš”μ²­ν•΄μ•Όν•˜λŠ” 상황이 λ˜μ—ˆλ‹€.
proxy λŠ” ν•œκ΅­νˆ¬μžμ¦κΆŒμ˜ openapivts μ£Όμ†Œλ§Œ μ μ–΄λ†“μ•˜μ—ˆλ‹€.

ERROR ❌

그러면 seibro 둜 μš”μ²­μ„ 보낼 λ•Œ μ—λŸ¬κ°€ λ‚œλ‹€.

seibro 둜 path 만 보낼 순 μ—†μœΌλ‹ˆ.. proxy 섀정을 ν•΄μ€˜μ•Όν•˜λŠ”λ°
μ–΄λ–»κ²Œ ν• κΉŒ 찾아보닀

Method 1 ❌

μ΄λ ‡κ²Œ ν•΄λ΄€λŠ”λ°

)

μ°Έκ³ : stackoverflow

CRA v2(Create-React-App) λΆ€ν„° λ°”λ€Œμ—ˆλ‚˜λ³΄λ‹€.

μ°Έκ³ : CRA V2 릴리즈! 무슨 λ³€κ²½ 사항이 μžˆμ„κΉŒ?

Method 2 βœ…

http-proxy-middleware λ₯Ό μ‚¬μš©ν•΄λ³΄μž.

  1. npm install http-proxy-middleware --save λ₯Ό μ΄μš©ν•΄ μ„€μΉ˜ν•œλ‹€.
  2. package.json 에 있던 "proxy" : " ... " 을 μ§€μš΄λ‹€.
  3. src 폴더 μ•ˆμ— setupProxy.js λ₯Ό λ§Œλ“ λ‹€.
  4. 거기에 proxy λ₯Ό μ—¬λŸ¬κ°œ λ“±λ‘ν•˜λ©΄ λœλ‹€!!
  5. μ½”λ“œλ₯Ό λ„£μ–΄λ³΄μž
  6. const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = (app) => {  
app.use(  
createProxyMiddleware('/oauth2',{  
target:'[https://openapivts.koreainvestment.com:29443'](https://openapivts.koreainvestment.com:29443'),  
changeOrigin:true  
})  
)  
app.use(  
createProxyMiddleware('/uapi',{  
target:'[https://openapivts.koreainvestment.com:29443'](https://openapivts.koreainvestment.com:29443'),  
changeOrigin:true  
})  
)  
app.use(  
createProxyMiddleware('/openapi',{  
target:'[http://api.seibro.or.kr'](http://api.seibro.or.kr'),  
changeOrigin:true  
})  
)  
}
  1. μ΄λ ‡κ²Œ ν•œ 뒀에 axios μ—λŠ” path 만 λ„£μ–΄μ£Όλ©΄ 잘 μž‘λ™ν•œλ‹€.

μ°Έκ³  :Create React App

끝

πŸ™‚?γ…Žγ…Ž

728x90
λ°˜μ‘ν˜•
LIST
Comments