Peter Valek
Peter Valek

Reputation: 87

Lumen - I'm getting CORS error when trying POST request with some header, but without header everything is ok

So my problem is: I Have Lumen server on subdomain api.domain.com After sending ajax request from domain.com to api.domain.com:

$.ajax({
            url: 'https://api.domain.com/login',
            type: 'post',
            headers: {
                'Authorization': 'someJWTTOKEN'
                'Content-Type': 'application/json'
            },
            data: {},
            dataType: 'json',
            success: function(result) {
                console.log('result');
                console.log(result);
            },
            error: function(error) {
                console.log(error);
            }
        });

Now I get CORS error: enter image description here

But when I remove Header from ajax request, everything works fine.

This works great:

   $.ajax({
                url: 'https://api.domain.com/login',
                type: 'post',
                headers: {
                },
                data: {},
                dataType: 'json',
                success: function(result) {
                    console.log('result');
                    console.log(result);
                },
                error: function(error) {
                    console.log(error);
                }
            });

Upvotes: 0

Views: 767

Answers (1)

Solomon Antoine
Solomon Antoine

Reputation: 574

I had this problem connecting my React app to my Lumen API but solved it by using this PHP Package. In the README they explain how to configure the package with Lumen. Legit took me like 2 minutes.

Upvotes: 1

Related Questions