配置中的 devServer 代理抛出 404 [英] devServer proxy in config throws 404

查看:76
本文介绍了配置中的 devServer 代理抛出 404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 src/vue.config.js

module.exports = {
  devServer: {
    proxy: {
      '/api': {
        target: 'http://localhost:8081',
        changeOrigin: true,
      },
    },
  },
};

我用

  axios.get('/api/parts')
    .then(result => commit('updateParts', result.data))
    .catch(console.error);

但我一直在接受

错误:请求失败,状态码为 404"

Error: "Request failed with status code 404"

我可以看到请求是发送到端口 8080 而不是 8081

And I can see the request is being made to port 8080 instead of 8081

我可以在浏览器中访问 api 没有问题

I can access the api in the browser with no problems

我该如何调试?

推荐答案

你的 vue.config.js 不应该在 src 文件夹中.它必须在您的项目的根目录中.只需移动文件.

Your vue.config.js is not supposed to be in the src folder. It must be in the root of your project. Simply move the file.

服务器的配置参考可以在这里找到:https://cli.vuejs.org/config/#devserver-proxy 但看来您实际上做得对.该文件位于错误的文件夹中.

The configuration reference for the server can be found here: https://cli.vuejs.org/config/#devserver-proxy but it seems you're actually doing it right. The file is just at the wrong folder.

这篇关于配置中的 devServer 代理抛出 404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆