K
K
kiranananda2020-12-23 20:56:26
CORS
kiranananda, 2020-12-23 20:56:26

CORS not working mazite requests?

I am writing a webcam for Laravel on Vue as a separate project. Accordingly, they are running on different domains.

Added middleware CORS in Laravel itself

public function handle(Request $request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Headers', '*')
            ->header('Access-Control-Allow-Methods', '*');
    }


Achieved that normal requests pass. But if I add the data parameter to the Axios request, then they kick me.

Axios({method: 'post', url: '/api/page/' + page, data: {name: 'hello'}})


How would you achieve normal operation of this whole thing? Then my mobile phones will cling to the application ...

XMLHttpRequest cannot load http://127.0.0.1:8000/api/page/pk due to access control checks.
Failed to load resource: Origin http://localhost:8080 is not allowed by Access-Control-Allow-Origin.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-12-23
@kiranananda

In the 8th lara, I didn’t seem to have any problems with cors.
https://laravel.com/docs/8.x/routing#cors
There is a separate config.

O
OCTAGRAM, 2021-01-13
@OCTAGRAM

For a POST request, you must first respond positively to the OPTIONS method. Does he work normally? In a normal router, this method may not go.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question