4
我想代理所有api/
請求http://localhost:3000
使用vue-axios
和vuex
。命令行上的輸出表示代理已經創建,但實際上並沒有代理正確的地址和404。Vue的代理webpack dev服務器
我已經的WebPack內的以下設置:
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: true,
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {
'api/': {
target: 'https://localhost:3000/api',
changeOrigin: true,
pathRewrite: {
'^/api':""
}
}
}
}
而且我的行爲的內部文件,我有:
import Vue from 'vue'
export const register = ({ commit }, user) => {
return new Promise((resolve, reject) => {
Vue.axios.post('users', user)
.then(res => {
console.log(res)
debugger
})
.catch(err => {
console.error(err)
debugger
})
})
}
控制檯輸出表明代理已經確定:
[HPM] Proxy created: /api -> https://localhost:3000/api
[HPM] Proxy rewrite rule created: "^/api" ~> ""
但是當我實際調用函數時,它返回http://localhost:8080/users 404 (Not Found)
這是什麼不正確?
我已經諮詢
這些解決方案都沒有奏效。
我聽說這可能是hmr的一個問題,但這似乎不太可能。
任何想法?
我曾嘗試以下組合:
'/api': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'api/': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'api/*': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'*/api/**': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'*': {
target: 'https://localhost:3000',
secure: false,
changeOrigin: true
},
'/api/*': {
target: 'http://localhost:3000',
changeOrigin: true
}
proxy: {
"/api": {
"target": {
"host": "localhost",
"protocol": 'http:',
"port": 3000
},
ignorePath: true,
changeOrigin: true,
secure: false
}
},
同樣的問題在這裏,仍然沒有解決方案 – Plastic