【发布时间】:2022-01-14 10:22:35
【问题描述】:
尝试将 PHP 与 Vue CLI 一起使用,我正在尝试复制: https://forum.vuejs.org/t/using-php-with-vue-cli/52842/3 但失败了。
我有这个文件夹结构:
-
我的应用程序/
- 公开/
- src/
- vue.config.js
-
返回/
- index.php
当我从 myapp/ 运行 npm run serve 时,我会转到 http://localhost:8080 并查看我的应用程序。
在另一个名为“back”的文件夹中,我有我的 php 文件。 我使用 mamp 运行服务器,并通过以下地址访问此文件夹:http://back:8888
在我的 vue.config.js 中有
module.exports = {
devServer: {
proxy: {
'^/api': {
target: 'http://back:8888',
changeOrigin: true,
logLevel: "debug"
}
}
}
};
据我了解,当我访问 http://localhost:8080/api 和 http://back:8888 时应该有相同的页面。
但我没有,我得到了 http://localhost:8080/api 的 404,然后返回:8888 就可以了。
在终端我有这个[HPM] GET /api -> http://back:8888
所以它确实检测到重定向。
最奇怪的是:
module.exports = {
devServer: {
proxy: {
'^/api': {
target: 'http://back:8888/index.php',
changeOrigin: true,
logLevel: "debug"
}
}
}
};
当我访问 localhost:8080/api 时,我的后台文件夹中确实有 index.php 的输出。
我在这里错过了什么?
谢谢
【问题讨论】: