Cors Policy

Closed Posted 3 years ago Paid on delivery
Closed Paid on delivery

Presently in my angular 9 application my post has the following header being set:

const httpOptions = {

headers: new HttpHeaders({

'Content-Type': 'application/json',

'Accept' : 'application/json'

})

};

Then in my laravel application, I have modified the [login to view URL] file as below:

protected function getRouteForMethods($request, array $methods)

{

if ($request->method() == 'OPTIONS') {

return (new Route('OPTIONS', $request->path(), function () use ($methods) {

//return new Response('', 200, ['Allow' => implode(',', $methods)]);

return new Response('', 200, [

'Allow' => implode(',', $methods),

'Access-Control-Allow-Origin' => '*',

'Access-Control-Allow-Credentials' => 'true',

'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS',

'Access-Control-Allow-Headers' => 'X-Requested-With, Content-Type, X-Auth-Token, Origin, Authorization'

]);

}))->bind($request);

}

$this->methodNotAllowed($methods);

}

Also in each of my laravel controller, I have included:

public function __construct(){

//header('Access-Control-Allow-Credentials: true');

header('Access-Control-Allow-Origin: *');

}

However, after deployment to my VPS running on Centos operating system, I receive the following error when accessing from my browser:

Access to XMLHttpRequest at '[login to view URL]' from origin '[login to view URL]' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

With the settings above, on the localhost, the error above is resolved. However, when deployed to the production environment the problem crops out.

You are required to work on this remotely.

AngularJS Laravel CentOs

Project ID: #25749906

About the project

4 proposals Remote project Active 3 years ago

4 freelancers are bidding on average $25 for this job

mho94

hi. I'm experienced in CORS, and I can resolve the issues of CORS at your production deployment. Can you please contact me. Thank you

$30 USD in 1 day
(13 Reviews)
4.5
raisdhaka

Hi, cors policy need to add at API, not at angular system. if you have access of that API, add header. if need my help, pls hire me. Thanks R

$35 USD in 1 day
(5 Reviews)
3.4
RajdeepWasekar

Hi This is a very simple solution. Just add the developer certificate in laravel. That will sort it out. Thanks

$15 USD in 7 days
(0 Reviews)
0.0
anjarwidiyatmoko

Hello, I have read your code, but perhaps something is missing need to check first. Contact me if you're interested for further discussion. Thanks.

$20 USD in 1 day
(0 Reviews)
0.0