12

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"
  },

1 Answer 1

15

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
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.