You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@knox.apache.org by David Morin <mo...@gmail.com> on 2018/07/30 21:47:28 UTC

need help for a rewrite rule

Hello,

I've got this url:

https://knox.XXXX/gateway/default/logsearch/scripts/collections/SchemaFieldList.js?ver=build.version

*that contains this:*

return Backbone.Collection.extend({
    model: SchemaField,
url: 'static/schema_fields.json'
  });

*And I'd like to replace by:*

return Backbone.Collection.extend({
    model: SchemaField,
url: '*logsearch*/static/schema_fields.json'
  });

because at the moment, I've got a 404. The url called by the browser is
this one:
https://knox.XXXX/gateway/default/static/schema_fields.json

What is the best way to handle this rewriting ?

Thanks in advance
David

Re: need help for a rewrite rule

Posted by David Morin <mo...@gmail.com>.
Thanks Billy !
I've adapted your example and that works

Le mar. 31 juil. 2018 à 19:52, Watson, Billy <Bi...@disney.com> a
écrit :

> One of the best examples of what you need is in the ambari UI config in
> github.
>
>
>
>
> https://github.com/apache/knox/blob/master/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/rewrite.xml
>
>
> https://github.com/apache/knox/blob/master/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml
>
>
>
> Match on the whole string and then apply the gateway path. Assuming that a
> leading slash won’t break things (it usually is neutral or even helps),
> then you can do something like this:
>
>
>
> <rule dir="OUT" name="LOGSEARCH/logsearch/schema_fields/outbound"
> pattern="static/schema_fields.json">
>
> <rewrite template="{$frontend[path]}/logsearch/static/schema_fields.json"/>
>
> </rule>
>
>
>
> That’s the most basic way. You may want to limit this to your javascript
> portion. If you do, you’ll need to add a filter and then add that filter to
> the service.xml.
>
>
>
> The most helpful docs for me were:
>
>
>
> http://kminder.github.io/knox/2015/11/16/adding-a-service-to-knox.html
>
>
> https://cwiki.apache.org/confluence/display/KNOX/2017/08/14/Understanding+Rewrite+Rules+for+Apache+Knox
>
> https://cwiki.apache.org/confluence/display/KNOX/Proxying+a+UI+using+Knox
>
>
>
>
>
> *Billy Watson*
>
>
>
>
>
> *From: *David Morin <mo...@gmail.com>
> *Reply-To: *"user@knox.apache.org" <us...@knox.apache.org>
> *Date: *Monday, July 30, 2018 at 5:47 PM
> *To: *"user@knox.apache.org" <us...@knox.apache.org>
> *Subject: *need help for a rewrite rule
>
>
>
> Hello,
>
>
>
> I've got this url:
>
>
>
>
> https://knox.XXXX/gateway/default/logsearch/scripts/collections/SchemaFieldList.js?ver=build.version
>
>
>
> *that contains this:*
>
>
>
> return Backbone.Collection.extend({
>
>     model: SchemaField,
>
> url: 'static/schema_fields.json'
>
>   });
>
>
>
> *And I'd like to replace by:*
>
>
>
> return Backbone.Collection.extend({
>
>     model: SchemaField,
>
> url: '*logsearch*/static/schema_fields.json'
>
>   });
>
>
>
> because at the moment, I've got a 404. The url called by the browser is
> this one:
>
> https://knox.XXXX/gateway/default/static/schema_fields.json
>
>
>
> What is the best way to handle this rewriting ?
>
>
>
> Thanks in advance
>
> David
>

Re: need help for a rewrite rule

Posted by "Watson, Billy" <Bi...@disney.com>.
One of the best examples of what you need is in the ambari UI config in github.

https://github.com/apache/knox/blob/master/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/rewrite.xml
https://github.com/apache/knox/blob/master/gateway-service-definitions/src/main/resources/services/ambariui/2.2.0/service.xml

Match on the whole string and then apply the gateway path. Assuming that a leading slash won’t break things (it usually is neutral or even helps), then you can do something like this:

<rule dir="OUT" name="LOGSEARCH/logsearch/schema_fields/outbound" pattern="static/schema_fields.json">
<rewrite template="{$frontend[path]}/logsearch/static/schema_fields.json"/>
</rule>

That’s the most basic way. You may want to limit this to your javascript portion. If you do, you’ll need to add a filter and then add that filter to the service.xml.

The most helpful docs for me were:

http://kminder.github.io/knox/2015/11/16/adding-a-service-to-knox.html
https://cwiki.apache.org/confluence/display/KNOX/2017/08/14/Understanding+Rewrite+Rules+for+Apache+Knox
https://cwiki.apache.org/confluence/display/KNOX/Proxying+a+UI+using+Knox


Billy Watson


From: David Morin <mo...@gmail.com>
Reply-To: "user@knox.apache.org" <us...@knox.apache.org>
Date: Monday, July 30, 2018 at 5:47 PM
To: "user@knox.apache.org" <us...@knox.apache.org>
Subject: need help for a rewrite rule

Hello,

I've got this url:

https://knox.XXXX/gateway/default/logsearch/scripts/collections/SchemaFieldList.js?ver=build.version

that contains this:

return Backbone.Collection.extend({
    model: SchemaField,
url: 'static/schema_fields.json'
  });

And I'd like to replace by:

return Backbone.Collection.extend({
    model: SchemaField,
url: 'logsearch/static/schema_fields.json'
  });

because at the moment, I've got a 404. The url called by the browser is this one:
https://knox.XXXX/gateway/default/static/schema_fields.json

What is the best way to handle this rewriting ?

Thanks in advance
David