Hi Ionic Community!
I was hoping I could get some help with configuring CORS correctly for WkWebview as I am having trouble debugging my configuration with the Play Framework.
When I run my app on an iOS device or simulator, I get “preflight response is not successful” errors. However, Android and browser settings work fine (including Chrome, FF, Safari and IE).
I initially tried an “open” policy as below, but did not have any luck.
cors {
pathPrefixes = ["/"]
allowedOrigins = null
allowedHttpMethods = null
allowedHttpHeaders = null
exposedHeaders = ["Access-Control-Allow-Origin"]
preflightMaxAge = 3 days
}
After reading https://ionicframework.com/docs/wkwebview/ I developed a configuration to match the following checklist:
- Adding localhost:8080 as an origin
- Whitelisting methods
- Whitelisting headers
- CORS preflight request (OPTION)
Thus I changed my configuration to:
pathPrefixes = ["/"]
allowedOrigins = ["http://localhost:8080"]
allowedHttpMethods = ["GET", "POST", "PUT", "OPTIONS", "HEAD"]
allowedHttpHeaders = ["Accept", "Content-Type", "Referer", "X-Requested-With", "X-Auth-Token"]
exposedHeaders = ["Access-Control-Allow-Origin"]
preflightMaxAge = 3 days
However I still get the preflight error as before, which leads me to believe I have not implemented CORS correctly in regards to the checklist.
Does this configuration correctly address the CORS checklist from above? Has anyone deployed an Ionic app with a Play Framework backend that successfully handles CORS for WkWebview?
Any help is appreciated! Thanks in advance