How to proxy requests to a separate backend server with Vue CLI?

Sometimes, we want to proxy requests to a separate backend server with Vue CLI.

In this article, we’ll look at how to proxy requests to a separate backend server with Vue CLI.

How to proxy requests to a separate backend server with Vue CLI?

To proxy requests to a separate backend server with Vue CLI, we can add the proxy options to vue.config.js.

For instance, we write

module.exports = {
  devServer: {
    proxy: {
      "/gists": {
        target: "https://api.github.com",
        secure: false,
      },
    },
  },
};

in vue.config.js to proxy all requests to /gists to https://api.github.com.

Conclusion

To proxy requests to a separate backend server with Vue CLI, we can add the proxy options to vue.config.js.