Giter Site home page Giter Site logo

Comments (21)

barretzhi avatar barretzhi commented on May 8, 2024 1

哈哈,我是这样做的

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

是否使用的PHP原生header()函数?
不能使用的函数

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

@hhxsv5 我看了 那个包没有使用原生的header()
_ _20180418084656

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

第三方包吗?文件发下。

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

@hhxsv5 https://github.com/palanik/lumen-cors

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

测试了,没问题。
4348e083-4a3e-4d40-bd94-87143f20851e

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

我也测试没问题,但请求几次就不行了
_ _20180418101752

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

_ _20180418103047

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

body数据都正常吗?怀疑代码没走到中间件。

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

@barretzhi 细聊 QQ群:698480528

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

body 正常的,我也在怀疑没走到中间件。 我发现服务启动后bootstarp/app.php 下的文件在每次请求的时候都不走

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

Dingo Api中干掉了Application的全局中间件。
https://github.com/dingo/api/blob/master/src/Routing/Adapter/Lumen.php#L253
目前还没有较好的办法解决,我再想想看

from laravel-s.

barretzhi avatar barretzhi commented on May 8, 2024

好的,谢谢

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

不用中间件实现CORS,直接Response对象带上Header吧。这是目前较理想的解决方案。

public function index(Request $req)
{
    $headers = [
        'Access-Control-Allow-Origin' => '*',
        //...
    ];
    $data = ['now' => time()];
    return response()->json($data, 200, $headers);
}

然后,再统一封装一个Trait来做响应。

from laravel-s.

dickwu avatar dickwu commented on May 8, 2024

跨域问题可以用nginx解决,这样又快又不需要引入那个包

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

@dickwu 也不错

from laravel-s.

Eli-jah avatar Eli-jah commented on May 8, 2024

Problem solved partially, at least by now. Here is the solution:

Coding @ config/laravels.php as follows:

'register_providers' => [
        /* middleware service providers */
        Dingo\Api\Provider\DingoServiceProvider::class,
        Dingo\Api\Provider\HttpServiceProvider::class,
        /* auth service providers */
        Illuminate\Auth\AuthServiceProvider::class,
        App\Providers\AuthServiceProvider::class,
        Tymon\JWTAuth\Providers\LaravelServiceProvider::class,
],

Git it a try, and wish it would work for you, too.

from laravel-s.

uniteweiwei avatar uniteweiwei commented on May 8, 2024

image

image

from laravel-s.

FlameMida avatar FlameMida commented on May 8, 2024

目前还是不支持dingo吗?

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 8, 2024

@FlameMida 是的

from laravel-s.

dengao123 avatar dengao123 commented on May 8, 2024

我这也是请求一段时间就报跨域错误,没用djingo。用的\Medz\Cors\Laravel\Middleware\ShouldGroup中间件.求大佬帮忙,卡了2,3天了。

from laravel-s.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.