[英]How to add axios proxy?
我正在嘗試向我的應用程序添加代理,因此當我對后端進行查詢時,不必查詢“https://localhost:5000/api/users”,我只需查詢'api/用戶'。 我將如何 go 這樣做? 以下是我的 package.json,我非常感謝任何有關如何修改它以進行此調整的指導。 謝謝!
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject",
"debug": "open 'rndebugger://set-debugger-loc?host=localhost&port=19001'"
},
"dependencies": {
"@expo-google-fonts/quicksand": "^0.1.0",
"@react-native-community/masked-view": "0.1.10",
"@react-navigation/bottom-tabs": "^5.11.7",
"@react-navigation/native": "^5.9.2",
"@react-navigation/stack": "^5.14.2",
"axios": "^0.21.1",
"expo": "~40.0.0",
"expo-app-loading": "^1.0.1",
"expo-font": "~8.4.0",
"expo-image-picker": "~9.2.0",
"expo-status-bar": "~1.0.3",
"moment": "^2.29.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-moment": "^1.1.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-dropdown-picker": "^3.8.0",
"react-native-gesture-handler": "~1.8.0",
"react-native-gifted-chat": "^0.16.3",
"react-native-reanimated": "~1.13.0",
"react-native-safe-area-context": "3.1.9",
"react-native-screens": "~2.15.2",
"react-native-web": "~0.13.12",
"react-navigation": "^4.4.3",
"react-redux": "^7.2.2",
"react-router-dom": "^5.2.0",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-thunk": "^2.3.0",
"uuid": "^8.3.2"
},
"devDependencies": {
"@babel/core": "~7.9.0"
},
"private": true
}
將proxy
選項添加到您的 axios 請求中,如下所示:
const res = await axios.get('/api/users', {
proxy: {
host: 'localhost',
port: 5000
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.