Return empty options response through htaccess
Many hybrid apps use the web container of the OS like WebView to render the app components. Those then also perform their API requests through the web container. Internally this means that every request is only done after an OPTIONS request to the same url and this means there has to be a handling in the API for it.
Or has there?
As it only has to be a successful response without any specific content, you can also move this "logic" to your infrastructure and don't have to clutter up your backend code. For example by putting the following into your .htaccess
:
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=204,L]
It simple redirects every incoming request with the OPTIONS
method to an empty 204
status response.
This won't work if you have to return any special headers on your responses even if they are static and could potentially be moved here as they are ignored here. For example if you would like to send CORS headers. If you've got a case like this, you will still need to go though your backend.