javascript - Parse URL which contain string of two URL -


i've node app , im getting in header following url , need parse it , change content of 3000 4000 ,how can since im getting "two" urls in req.headers.location

"http://to-d6faorp:51001/oauth/auth?response_type=code&redirect_uri=http%3af%2fmo-d6fa3.ao.tzp.corp%3a3000%2flogin%2fcallback&client_id=x2.node"

the issue cannot use replace since value can changed (dynmaic value ,now 3000 later can value...)

if part of url need change going parameter of redirect_uri need find index of second %3a comes after it.

javascript indexof has second parameter 'start position', can first indexof 'redirect_uri=' string, , pass position in next call indexof first '%3a' , pass result next call %3a comes before '3000'. once have positions of tokens looking should able build new string using substrings... first substring end of second %3a , second substring index of %2f comes after it.

basically, building string cutting string so:

"http://to-d6faorp:51001/oauth/auth?response_type=code&redirect_uri=http%3af%2fmo-d6fa3.ao.tzp.corp%3a"

"%2flogin%2fcallback&client_id=x2.node"

... , appending in whatever port number trying put in.

hope helps.

this code should want:

var strurl = "http://to-d6faorp:51001/oauth/auth?response_type=code&redirect_uri=http%3af%2fmo-d6fa3.ao.tzp.corp%3a3000%2flogin%2fcallback&client_id=x2.node";  var strnewurl = strurl.substring(0,strurl.indexof("%3a", strurl.indexof("%3a", strurl.indexof("redirect_uri") + 1) + 1) + 3) + "4000" + strurl.substring(strurl.indexof("%2f",strurl.indexof("%3a", strurl.indexof("%3a", strurl.indexof("redirect_uri") + 1) + 1) + 3)); 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -