Hi,
I have setup a Stingray Traffic Manager to load balance a cluster of Node.js instances running on Joyant's Cloud infrastructure. I am currently running into, "No 'Access-Control-Allow-Origin' errors". I understand why this is happening. I need to enable my virtual server to allow Cross Origin Resource Sharing (CORS). I don't know where to do that in the Stingray admin console. Here is how I am currently managing my setup:
1) I Created a virtual server mapped to a subdomain and DNS, for example, "dashboard.mydomain.com".
2) Next I created 2 instances in my Pool, "dashboard1.mydomain.com" and "dashboard2.mydomain.com".
3) When I point my browser to the virtual server, "dashboard.mydomain.com", I get rerouted to "dashboard2.mydomain.com" as expected. I have never been rerouted to the "dashboard1" instance. When I initially set up the pool, I added "dashboard1" then "dashboard2". Overall, I'm assuming this is ok. I guess when the load increases "dashboard1" will eventually be used?
My application is written in JavaScript and uses XHR to make AJAX requests. XHR honors the same origin policy so the server must allow cross domain access by setting the following response headers to enable CORS:
'Access-Control-Allow-Origin', '*'
'Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE'
My cluster instances, "dashboard1.mydomain.com" and "dashboard2.mydomain.com" are already configured for CORS. I can independently make cross origin requests to those servers without issue. However, when a cross domain request is made against the virtual server, "dashboard.mydomain.com", I get the "No 'Access-Control-Allow-Origin' errors". I do have the ability to SSH into the virtual server, but I don't know how to configure it for CORS or know what web server it runs. Any help would be greatly appreciated. Thanks.
Maxx
Solved! Go to Solution.
Maxx,
I have spent some time reading up on CORS (I haven't come across it myself in my time working with ADCs) but as far as I can tell, this should just work.
STM will honour and forward any headers set by the server or client. Have you tried tracing the connection from the client side to see if the headers are present?
You could use a little bit of TrafficScript to log the HTTP Headers from the client and server out to the STM log file to see what is going on. STM won't remove headers from the server unless configured explicitly to do so.
Here is a TS snippet you can use to log the HTTP Client and Server headers out to the STM log file to see what is going in. Just add the rule and attach it to your vserver as a request AND a response rule:
$rule_state = rule.getstate();
if ($rule_state == "REQUEST"){
$client_ip = request.getRemoteIP();
$req_headers = http.getHeaders();
#
log.info("Request received from: " . $client_ip . " with the following headers: " . lang.dump($req_headers));
}
if ($rule_state == "RESPONSE"){
$client_ip = request.getRemoteIP();
$resp_headers = http.getHeaders();
#
log.info("Response received from server for request from: " . $client_ip . " with the following headers: " . lang.dump($resp_headers));
}
your STM log file will have the HTTP Request and Response headers logged with the format "Header Name" => "Value".
Mine looks like this (although I don't have any CORS headers in my logs):
INFO | 04/Aug/2014:14:06:31 +1000 | INFO | Rule dump_http_headers, Virtual Server vs_http: Response received from server for request from: 1.2.3.4 with the following headers: [ "Accept-Encoding" => "gzip,deflate,sdch", "Content-Length" => "0", "Connection" => "keep-alive", "Cookie" => "WEBSITE_WEBACCESS=AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH; X-Mapping-gbooldlg=ZZZZYYYYXXXXWWWWVVVVUUUU", "Accept-Language" => "en,en-US;q=0.8", "X-Cluster-Client-Ip" => "1.2.3.4", "Host" => "www.mywebsite.com", "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36", "Accept" => "*/*" ] | stm001.company.com |
INFO | 04/Aug/2014:14:06:31 +1000 | INFO | Rule dump_http_headers, Virtual Server vs_http: Request received from: 1.2.3.4 with the following headers: [ "Accept-Encoding" => "gzip,deflate,sdch", "Content-Length" => "0", "Connection" => "keep-alive", "Cookie" => "WEBSITE_WEBACCESS=AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH; X-Mapping-gbooldlg=ZZZZYYYYXXXXWWWWVVVVUUUU", "Accept-Language" => "en,en-US;q=0.8", "Host" => "www.mywebsite.com", "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36", "Accept" => "*/*" ] | stm001.company.com |
Let us know how you go...
Maxx,
I have spent some time reading up on CORS (I haven't come across it myself in my time working with ADCs) but as far as I can tell, this should just work.
STM will honour and forward any headers set by the server or client. Have you tried tracing the connection from the client side to see if the headers are present?
You could use a little bit of TrafficScript to log the HTTP Headers from the client and server out to the STM log file to see what is going on. STM won't remove headers from the server unless configured explicitly to do so.
Here is a TS snippet you can use to log the HTTP Client and Server headers out to the STM log file to see what is going in. Just add the rule and attach it to your vserver as a request AND a response rule:
$rule_state = rule.getstate();
if ($rule_state == "REQUEST"){
$client_ip = request.getRemoteIP();
$req_headers = http.getHeaders();
#
log.info("Request received from: " . $client_ip . " with the following headers: " . lang.dump($req_headers));
}
if ($rule_state == "RESPONSE"){
$client_ip = request.getRemoteIP();
$resp_headers = http.getHeaders();
#
log.info("Response received from server for request from: " . $client_ip . " with the following headers: " . lang.dump($resp_headers));
}
your STM log file will have the HTTP Request and Response headers logged with the format "Header Name" => "Value".
Mine looks like this (although I don't have any CORS headers in my logs):
INFO | 04/Aug/2014:14:06:31 +1000 | INFO | Rule dump_http_headers, Virtual Server vs_http: Response received from server for request from: 1.2.3.4 with the following headers: [ "Accept-Encoding" => "gzip,deflate,sdch", "Content-Length" => "0", "Connection" => "keep-alive", "Cookie" => "WEBSITE_WEBACCESS=AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH; X-Mapping-gbooldlg=ZZZZYYYYXXXXWWWWVVVVUUUU", "Accept-Language" => "en,en-US;q=0.8", "X-Cluster-Client-Ip" => "1.2.3.4", "Host" => "www.mywebsite.com", "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36", "Accept" => "*/*" ] | stm001.company.com |
INFO | 04/Aug/2014:14:06:31 +1000 | INFO | Rule dump_http_headers, Virtual Server vs_http: Request received from: 1.2.3.4 with the following headers: [ "Accept-Encoding" => "gzip,deflate,sdch", "Content-Length" => "0", "Connection" => "keep-alive", "Cookie" => "WEBSITE_WEBACCESS=AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHH; X-Mapping-gbooldlg=ZZZZYYYYXXXXWWWWVVVVUUUU", "Accept-Language" => "en,en-US;q=0.8", "Host" => "www.mywebsite.com", "User-Agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36", "Accept" => "*/*" ] | stm001.company.com |
Let us know how you go...