Hey Guys,
Im running my API from Laravel and using the CORS package here
The config file reads as follows:
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'exposedHeaders' => [],
'maxAge' => 0,
'hosts' => [],
and i have added the CORS middleware to my routes
Everything works fine in Postman, my API returns me a token, but when i run my Ionic 2 app, im gettting the following
No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:8100 ’ is therefore not allowed access. The response had HTTP status code 422
Ive also tried ionic upload and running it from my phone but still no luck.
Any help would be greatly appreciated.
Cheers,
Try this link that might helps you.
Try to use chrome with --disable-web-security
you will find many articles on how to disable-web-security of chrome for only development purpose…
assuming you are using MAC machine…
try this command on terminal…
open -n -a “Google Chrome” --args --user-data-dir=/tmp/temp_chrome_user_data_dir_for_cordova http://localhost:8100/ --disable-web-security
which opens another instance of chrome with disabled security and there is no CORS issue any more… as per I know this command will not hamper y…
(if you are working on MAC machine)
or this
This link might help you to disable web security of chrome on Windows machine.
Read the first comment on this link.
And another thing is if you facing CORS issue io browser, first try to deploy the app on a real device. Most probably it works fine on a real device. This happens only because of browser’s security settings it avoids you for CORS.
Firstly check whether your code working on a real device. If it works properly then create another instance of chrome with disabled security followi…
(if you are working on windows machine)
3 Likes
Glad this solution work for you.
Happy Coding
timsar
February 21, 2018, 8:43am
5