laravel 5.5 axios共享托管子文件夹api无法正常工作

时间:2018-03-23 03:58:04

标签: laravel

我在localhost上创建了全新的laravel 5.5项目,所有工作,api,路由,身份验证等。

我通过以下方式将其上传到我的共享主机上 https://www.youtube.com/watch?v=6g8G3YQtQt4教程,以及所有工作。除了app.js上的axios请求

它说

找不到

https://domainname/oauth/clients https://domainname/oauth/clients未找到 https://domainname/oauth/tokens未找到 https://domainname/oauth/scopes未找到

我的工作是通过添加子域来配置public / js / app.js代码。

 axios.get('[subdomain]/oauth/clients') <-- add manually

并且它正在运行但是这个目录问题的任何简单解决方案?谢谢

2 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,这就是我解决问题的方法:

在我的主要php页面中,我添加了我的基本网址:

<script>
 var flagsUrl = '{{ env('APP_URL') }}'; //this is the url from .env file
</script>

所以你可以像这样更改你的js文件:

axios.get(flagsUrl + '/oauth/clients');

答案 1 :(得分:0)

您可以在resources / assets / js / bootstrap.js中设置axios的基本URL

windows.axios.defaults.baseURL = 'https://yoursubdomain'

示例:

window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'; 
window.axios.defaults.baseURL = 'https://subdomain';

然后您可以使用:

axios.get('oauth/clients');
相关问题