How to configure Vue cli DevServer proxying of different urls to a single api server
The application on the vue cli goes to the api server. Here are the vue.config settings.js
module.exports = {
devServer: {
// Бэкенд сервер
proxy: {
"^/api/*": {
target: 'https://api.myserver.pro/',
ws: true,
changeOrigin: false
}
},
},
};
There are several roots
{ path: '/orders', name: 'orders', component: () => import('../views/orders.vue'), meta: { layout: 'MainLayout' } },
{ path: '/order/:id', name: 'order', component: () => import('../views/order.vue'), meta: { layout: 'MainLayout' } },
If I send an axios request from the orders page, everything works fine
await axios.get('api/orders/')
.then(response => {
...
})
Request from the local machine http://localhost:8080/orders goes to https://api.myserver.pro/api/orders and everything is ok
If I send an axios request from the order/2 page
await axios.get('api/order/2')
.then(response => {
...
})
Then the request goes with http://localhost:8080/order/2 on https://api.myserver.pro/order/api/order/1 and damn it, it doesn't work !!! Tell me how to direct it to https://api.myserver.pro/api/order/1? Set axios.defaults.baseUrl = "https://api.myserver.pro" it doesn't help! I do not know in general what to do)?
0
Author: Сергей Хохлов, 2021-01-29