- I am using the
(This is using the remote devices feature by Chrome to inspect requests from the app)
- Initially, the requests wouldn't even send and it would error out before then and so I setup my network security configuration for Android and that removed the initial error but now it keeps failing on preflight
- My suspcion is that it might be related to the fact that the requests on the app are being sent from
http://localhost
but I'm not sure how to resolve this. Can you force it to use an SSL? If so, how? - My CORS setup for Laravel is more leniant than the default CORS config that Laravel ships with:
return [ 'paths' => ['*'], 'allowed_methods' => ['*'], 'allowed_origins' => ['*'], 'allowed_origins_patterns' => [], 'allowed_headers' => ['*'], 'exposed_headers' => [], 'max_age' => 0, 'supports_credentials' => false, ];
CodePudding user response:
The issue was related to SSL/TLS pinning which axios doesn't deal with as per this comment.
The Ionic Native HTTP plugin handles the pinning natively and that worked for but of course it makes use of Cordova which isn't available on your non-mobile devices.
There were two potential solutions:
- Implement SSL/TLS pinning natively
- Create a service/factory which determines whether we want to use axios or the native plugin
I opted for
#2
- if you want information regarding#1
, see this answer.The following method for me determines which HTTP wrapper to use:
static makeRequest() { return isPlatform('cordova') ? cordovaHttpService : axiosHttpService; }
Of course, that can be amended with each specific case.