Very Slow App RESTful API with CORS


I’m developing a NC App which provides several RESTful APIs, some are GET and others are POST.
I followed the developer documentation in
I needed to add @CORS to my APIs since the client has different origin.
The requests to the API is sometimes extremely slow (almost 30 sec), and sometimes “magically” a matter of one second.
When I remove the @CORS annotation and use a local client then I get no such problem.
Here is my API Controller constructor:

    public function __construct($appName, IRequest $request) {
                'GET, POST',
                'Authorization, Content-Type, Accept',

Any ideas?

CORS requires another request, check your networks tab or whatever client you are using and look for the first OPTIONS request. Then check which request takes longer and debug from there

The preflighted OPTIONS is not the slow one. The problem is in the POST and GET requests.

I’d try to profile it and check where the slowdown occurs.

Hey there, did you guys get to the bottom of this?

@shak what was it that made your CORS request slow?