如何与使用Lumen构建的后端交流并与Vue Frontend一起使用Apache Virtual主机?

发布于 2025-02-09 05:21:51 字数 1290 浏览 1 评论 0原文

我有一个vue前端,我想通过它与灯具建造的后端进行通信。我在Apache虚拟主机上有后端。这是本地开发设置。虚拟主机有效,我可以从http://dawn.axeapi.com/中访问它,而Postman可以使用它。

我已经将vue_app_api设置为http://dawn.axeapi.com/.env文件中。 VUE应用程序正在使用npm运行服务

我在“控制台”和“开发人员工具”中的“网络”选项卡中遇到了以下错误。

”输入图像在此处“

”在此处输入图像说明”

但是,如果我双击请求(例如3304272),我可以从后端看到JSON数据。

如果我使用php -s localhost:8000 -t public和更新vue_app_api相应地,一切都应根据应有的工作。

  • 这是因为CORS吗?
  • Apache配置会影响这吗?

我在VUE文档中阅读,如果前端和后端API服务器未在同一主机上运行,​​则需要在开发过程中对API服务器的请求进行代理。因此,我尝试添加

devServer: {
    proxy: 'http://dawn.axeapi.com/'
  }

vue.config.js中,但没有起作用。

我正在运行与MacOS一起发货的Apache。

我在这里想念什么?

I have a Vue frontend through which I want to communicate with a backend built with lumen. I have the backend on apache virtual host. It is a local development setup. The virtual host works and I can access it from http://dawn.axeapi.com/ and postman works fine with it.

I've set VUE_APP_API to http://dawn.axeapi.com/ in the .env file. The Vue app is being served with npm run serve.

I am getting following errors in the console and the network tab in developer tools.

Errors on console

enter image description here

enter image description here

But if I double click the requests (e.g. 3304272), I can see JSON data from the backend.

If I serve the backend with php -S localhost:8000 -t public and update VUE_APP_API accordingly, everything works as it should.

  • Is this because of CORS?
  • Does apache configuration affect this?

I read in Vue documentation that API requests to the API server need to be proxied during development if the frontend and the backend API server are not running on the same host. So I tried adding

devServer: {
    proxy: 'http://dawn.axeapi.com/'
  }

to vue.config.js but didn't work.

I am running Apache that ships with macOS.

What am I missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

血之狂魔 2025-02-16 05:21:51

对于任何运行Apache乘MacOS运行的人,请禁用这些Apache模块,并且应该可以使用。我必须禁用全部八个。您可以一次尝试。

mod_authn_file.so
mod_authn_core.so
mod_authz_host.so
mod_authz_groupfile.so
mod_authz_user.so
mod_access_compat.so
mod_auth_basic.so
mod_reqtimeout.so

For anyone running Apache that ships with macOS, disable these Apache modules and it should work. I had to disable all eight. You can try one at a time.

mod_authn_file.so
mod_authn_core.so
mod_authz_host.so
mod_authz_groupfile.so
mod_authz_user.so
mod_access_compat.so
mod_auth_basic.so
mod_reqtimeout.so
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文