How to set window.location in apigee javascript policy

Not applicable

How to set window.location in apigee javascript policy? As window.location= <url> not working in JS policy. please give me some way to change the location in browser.

Solved Solved
1 4 615
1 ACCEPTED SOLUTION

Setting window.location makes sense for JS code that runs within the browser.

The JS code in Apigee Edge obviously doesn't run in the browser. It is possible, though, for a browser (via XHR) to invoke APIs or URLs managed by Apigee Edge. In that case, You can return a 302 Status Code with the Location header set to the url you want to redirect to.

https://en.wikipedia.org/wiki/HTTP_location

View solution in original post

4 REPLIES 4

@zalak pathak , Window.location is specific to browser. It doesn't make sense to use window.location in Apigee JS policy. What exactly are you trying to achieve in Apigee Edge ?

@Anil Sagar

Hi Anil,

I want to redirect all http requests to https so that it would be secure. So, i added JS policy in which i wrote below:

var req_verb = context.getVariable('request.verb'); var req_scheme = context.getVariable('client.scheme'); var req_host = context.getVariable('request.header.host'); var req_request_uri = context.getVariable('request.uri'); var req_url = "https://" + req_host + req_request_uri; context.setVariable('target.url',req_url);

So, now it is internally calling https and gets the response

but it is not changing browser url and not showing [Secure] ahead of url like attached image. So, i want to change the browser url to https.secure-url-https.png

Setting window.location makes sense for JS code that runs within the browser.

The JS code in Apigee Edge obviously doesn't run in the browser. It is possible, though, for a browser (via XHR) to invoke APIs or URLs managed by Apigee Edge. In that case, You can return a 302 Status Code with the Location header set to the url you want to redirect to.

https://en.wikipedia.org/wiki/HTTP_location

Thanks @Sean Davis