Forum Discussion
Getting around CORS with IRULES
- Nov 13, 2013
you can use the ProxyPassV10 irule for this.
your datagroup content would look like this: www.acmecorp.com/api/ api.acmecorp.com/ pool_api_servers
the virtual server's default pool should be the one for the www.acmecorp.com servers and you must use a oneconnect profile in the VS as well.
the proxypass irule will rewrite any request going to www.acmecorp.com/api/XYZ to api.acmecorp.com/XYZ and send it to the pool pool_api_servers proxypass will also take care of the location header in http redirects and rewrite it for you.
If I may add, if I understand you correctly, the Ajax is a client side thing. Script in the response content from www.acmecorp.com causes the client to make an Ajax call to api.acmecorp.com, but the client's firewall is stripping out the headers that are allowing this cross origin request to happen. So instead of the client making the request, you want the www.acmecorp.com VIP to make the request. If that's true, then I think you were on the right track to begin with, with a few modifications:
when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] starts_with "/api" } {
HTTP::header replace Host "api.acmecorp.com"
HTTP::uri [string map {"/api" ""} [HTTP::uri]]
virtual API_VIP
}
}
This will cause all "/api" requests to swing over to the API_VIP virtual server with the appropriate Host header and URI.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com