안녕하세요 G1N4입니다 :-)
[발생상황]
클라이언트(3000)에서 http-proxy-middleware를 이용하여 서버(5000) 페이지의 내용을 console에 노출을 구현하는 과정에서 서버(5000)으로 넘어가지않고 클라이언트(3000)에 머물러서 404 (not found)를 만난 상황입니다.
[해결완]
setupPorxy.js 파일 내용의 한줄만 수정하여 404 지옥으로부터 벗어날 수 있었다.
//기존 404에러 유발 코드
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
})
);
};
//수정 후
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
createProxyMiddleware({
target: 'http://localhost:5000',
changeOrigin: true,
pathFilter: '/api/',
})
);
};
도움이 되셨길 바라며, 그럼 다음 글에서 만나요 ;-)
[참조링크]
Proxying API Requests in Development | Create React App
http-proxy-middleware - npm
'Tech' 카테고리의 다른 글
Uncaught SyntaxError: Unexpected token '<' (at jquery ...) (0) | 2025.05.21 |
---|---|
최초커밋 메세지 수정 (0) | 2025.05.12 |
Windows(윈도우) SSH키 생성 및 github 연결 (0) | 2025.05.11 |
MongoDB 계정 관리(사이트에서) / 클러스터 삭제 (0) | 2025.05.09 |
Failed to load resource: the server responded with a status of 403 () (0) | 2023.05.17 |