You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@knox.apache.org by "Watson, Billy" <Bi...@disney.com> on 2018/07/26 16:10:01 UTC
Complicated Javascript Rewrite
Hello,
In trying to rewrite some javascript, there are multiple places where a path is used as a raw string and as a value somewhere else in the code. For instance,
key: "searchPath",
get: function() {
return "jobs"
}
And:
type: "jobs"
I want to replace the first “jobs”, but not the second one. The best I could come up with was this:
<rule dir="OUT" name="SERVICE/service/outbound/searchpath/jobs">
<match pattern="return"jobs" />
<rewrite template="return"{$frontend[path]}/jobs"/>
</rule>
<filter name="SERVICE/service/outbound/href">
<content type="application/javascript">
<apply path="return"jobs" rule="SERVICE/service/outbound/searchpath/jobs" />
This results in:
return "{$frontend[path]}/jobs"
The {$frontend[path]} shows up raw instead of being replaced. If I put that at the beginning of the template string, it gets replaced, but not if I put it where I need it. How can I work around this or should I look at contributing some code back to knox to change this behavior?
By the way, I hardcoded /gateway/{topology}/service into the rewrite template, which of course answers my own question. But I’m looking for a better workaround in case I need to use this service across topologies.
Thanks,
Billy Watson
Lead Platform Engineer, Parks Data Platform
Walt Disney Attractions Technology
7055 S Kirkman Rd, 225B, Orlando, FL 32819
Re: Complicated Javascript Rewrite
Posted by "Watson, Billy" <Bi...@disney.com>.
I can’t do that yet because of our version of Knox (0.6.0), but after we upgrade to 1.1 or after I will try it.
Thanks!
Billy Watson
From: Sandeep Moré <mo...@gmail.com>
Reply-To: "user@knox.apache.org" <us...@knox.apache.org>
Date: Thursday, July 26, 2018 at 1:52 PM
To: "user@knox.apache.org" <us...@knox.apache.org>
Subject: Re: Complicated Javascript Rewrite
Hello Billy,
You can use the variable $infix<https://cwiki.apache.org/confluence/display/KNOX/2017/08/14/Understanding+Rewrite+Rules+for+Apache+Knox#UnderstandingRewriteRulesforApacheKnox-$infix> instead of $frontend.
for e.g. {$infix[return",url,jobs"]}
Best,
Sandeep
On Thu, Jul 26, 2018 at 12:10 PM Watson, Billy <Bi...@disney.com>> wrote:
Hello,
In trying to rewrite some javascript, there are multiple places where a path is used as a raw string and as a value somewhere else in the code. For instance,
key: "searchPath",
get: function() {
return "jobs"
}
And:
type: "jobs"
I want to replace the first “jobs”, but not the second one. The best I could come up with was this:
<rule dir="OUT" name="SERVICE/service/outbound/searchpath/jobs">
<match pattern="return"jobs" />
<rewrite template="return"{$frontend[path]}/jobs"/>
</rule>
<filter name="SERVICE/service/outbound/href">
<content type="application/javascript">
<apply path="return"jobs" rule="SERVICE/service/outbound/searchpath/jobs" />
This results in:
return "{$frontend[path]}/jobs"
The {$frontend[path]} shows up raw instead of being replaced. If I put that at the beginning of the template string, it gets replaced, but not if I put it where I need it. How can I work around this or should I look at contributing some code back to knox to change this behavior?
By the way, I hardcoded /gateway/{topology}/service into the rewrite template, which of course answers my own question. But I’m looking for a better workaround in case I need to use this service across topologies.
Thanks,
Billy Watson
Lead Platform Engineer, Parks Data Platform
Walt Disney Attractions Technology
7055 S Kirkman Rd, 225B, Orlando, FL 32819
Re: Complicated Javascript Rewrite
Posted by Sandeep Moré <mo...@gmail.com>.
Hello Billy,
You can use the variable $infix
<https://cwiki.apache.org/confluence/display/KNOX/2017/08/14/Understanding+Rewrite+Rules+for+Apache+Knox#UnderstandingRewriteRulesforApacheKnox-$infix>
instead of $frontend.
for e.g. {$infix[return",url,jobs"]}
Best,
Sandeep
On Thu, Jul 26, 2018 at 12:10 PM Watson, Billy <Bi...@disney.com>
wrote:
> Hello,
>
>
>
> In trying to rewrite some javascript, there are multiple places where a
> path is used as a raw string and as a value somewhere else in the code. For
> instance,
>
>
>
> key: "searchPath",
>
> get: function() {
>
> return "jobs"
>
> }
>
>
>
> And:
>
>
>
> type: "jobs"
>
>
>
> I want to replace the first “jobs”, but not the second one. The best I
> could come up with was this:
>
>
>
>
>
> <rule dir="OUT" name="SERVICE/service/outbound/searchpath/jobs">
>
> <match pattern="return"jobs" />
>
> <rewrite template="return"{$frontend[path]}/jobs"/>
>
> </rule>
>
>
>
> <filter name="SERVICE/service/outbound/href">
>
> <content type="application/javascript">
>
> <apply path="return"jobs"
> rule="SERVICE/service/outbound/searchpath/jobs" />
>
>
>
>
>
> This results in:
>
>
>
> return "{$frontend[path]}/jobs"
>
>
>
> The {$frontend[path]} shows up raw instead of being replaced. If I put
> that at the beginning of the template string, it gets replaced, but not if
> I put it where I need it. How can I work around this or should I look at
> contributing some code back to knox to change this behavior?
>
>
>
> By the way, I hardcoded /gateway/{topology}/service into the rewrite
> template, which of course answers my own question. But I’m looking for a
> better workaround in case I need to use this service across topologies.
>
>
>
> Thanks,
>
>
>
> *Billy Watson*
>
> Lead Platform Engineer, Parks Data Platform
>
> Walt Disney Attractions Technology
>
> 7055 S Kirkman Rd, 225B, Orlando, FL 32819
>