Reputation: 421
I have a Vue project from @vue/cli
3.x.
The proxy I defined in package.json
based on this article is not working. The destination server doesn't see the API request.
What am I missing here?
The vue file:
<script lang="ts">
import { Component, Prop, Vue } from 'vue-property-decorator';
import VueResource from 'vue-resource';
Vue.use(VueResource);
@Component
export default class HelloWorld extends Vue {
@Prop() private msg!: string;
constructor() {
super();
this.$http.post('/api');
}
}
</script>
package.json:
"proxy": {
"/api": "http://localhost:9000/api"
},
Upvotes: 12
Views: 15854
Reputation: 138326
The article likely refers to an outdated method of setting up the proxy. The latest version of @vue/cli
(currently 3.0.0-rc.3
) has a new method of configuring the dev server.
For an equivalent setup of that proxy, create vue.config.js
(if it doesn't exist already) with the following contents:
module.exports = {
devServer: {
proxy: {
'/api': {
target: 'http://localhost:9000',
ws: true,
changeOrigin: true
}
}
}
}
Upvotes: 15