首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Laravel 7网络路线CORS问题

Laravel 7网络路线CORS问题
EN

Stack Overflow用户
提问于 2020-10-09 10:37:45
回答 3查看 358关注 0票数 0

我在apache服务器上尝试了laravel项目。

我克隆了我的项目

代码语言:javascript
复制
sudo -u www-data git clone ******* laravel

午餐作曲家

代码语言:javascript
复制
sudo -u www-data composer install --no-dev --optimize-autoloader

午餐npm与webpack

代码语言:javascript
复制
sudo -u www-data npm install
sudo -u www-data npm run production

创建.env

代码语言:javascript
复制
sudo -u www-data cp .env.example .env

生成键

代码语言:javascript
复制
sudo -u www-data php artisan key:generate
sudo -u www-data php artisan config:cache

在克隆我的项目并安装了所有包之后,我配置了.htaccess

代码语言:javascript
复制
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    RewriteBase /laravel/

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

和000-default.conf

代码语言:javascript
复制
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/laravel/public

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Alias /laravel /var/www/html/laravel/public/
<Directory "/var/www/html/laravel/public">
        AllowOverride All
        allow from all
        Options +Indexes
</Directory>

但是当我尝试登录时,我有一个500错误。

有人对此有解释吗?

更新1

我忘了这么做:

代码语言:javascript
复制
sudo -u www-data php artisan passport:install

但是现在我所有的web路由都有这个错误。

更新2

我所有的网络线路都有127.0.0.1:8000。但我在制作,我不应该有这个,不是吗?

更新3

我安装了水果蛋糕/拉拉

代码语言:javascript
复制
sudo composer remove barryvdh/laravel-cors fruitcake/laravel-cors
sudo -u www-data composer require fruitcake/laravel-cors

我允许CORS在app/Http/Kernel.php中使用您的所有路由。

代码语言:javascript
复制
protected $middleware = [
  \Fruitcake\Cors\HandleCors::class,
    // ...
]

我重新加载了我的Laravel配置并允许我的更改反映

代码语言:javascript
复制
sudo -u www-data php artisan config:cache

对于mapApiRoutes来说,这是工作,而不是mapWebRoutes。如何修复mapWebRoutes?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-10-14 14:04:06

我太蠢了..。

在我的份上,我有这个

代码语言:javascript
复制
created() {
            axios.get('http://127.0.0.1:8000/tasksList')
                .then(response => this.tasks = response.data)
                .catch(error => console.log(error));
        },

但是,在我的.env里

代码语言:javascript
复制
APP_URL=http://*****.*****.***:8080

我修正了我的成分

代码语言:javascript
复制
created() {
            axios.get('/tasksList')
                .then(response => this.tasks = response.data)
                .catch(error => console.log(error));
        },

现在是工作了。

票数 0
EN

Stack Overflow用户

发布于 2020-10-09 11:01:04

这是:

代码语言:javascript
复制
allow from all

..。是Apache2.2语法。在Apache 2.4中,请使用:

代码语言:javascript
复制
Require all granted

文档中的信息

票数 1
EN

Stack Overflow用户

发布于 2020-10-09 13:21:05

我猜不需要允许和要求,但我在所有的项目中都使用了类似的配置,而且它正在工作

AllowOverride所有订单允许,拒绝

人人都允许

要求所有的批准

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64278364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档