...
$prefix - This function enhances the $frontend function just like $import but gives the ability to choose a prefix (unlike a constant @import in case of $import) e.g.
Code Block <rewrite template="{$prefix[',url]}/zeppelin/components/{**}?{**}"/>
- $prefix[PREFIX, url] - Adds a supplied PREFIX to the frontend url, e.g. in above case the rewritten url would be 'https://localhost:8443/
zeppelin/components/navbar/navbar.html?v=1498928142479' (mind the single tick ' )
- $prefix[PREFIX, url] - Adds a supplied PREFIX to the frontend url, e.g. in above case the rewritten url would be 'https://localhost:8443/
Rules Filter
Sometimes you want the ability to rewrite the *.js, *.css and other non-html pages. FIlters are a way to rewrite these non-html files. FIlters are based on the content-type of the page.
These are the different types of filters that are supported by Apache Knox.
There are three declarations needed for filters,
- Filter declaration, the Content-Type and the pattern to apply the filter to - rewrite.xml
- Rewrite rule to apply to matched patter - rewrite.xml
- Path to apply the filter to and to be applied on response or request body - service.xml
The is an example of Filters used in Proxying Zeppelin UI, the relevant code snippets in rewrite.xml and service.xml files are:
Code Block | ||
---|---|---|
| ||
<!-- Filters -->
<rule dir="OUT" name="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/home" >
<rewrite template="{$frontend[path]}/zeppelin/app/home/home.html"/>
</rule>
<rule dir="OUT" name="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/notebook" >
<rewrite template="{$frontend[path]}/zeppelin/app/notebook/notebook.html"/>
</rule>
<rule dir="OUT" name="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/jobmanager" >
<rewrite template="{$frontend[path]}/zeppelin/app/jobmanager/jobmanager.html"/>
</rule>
<filter name="ZEPPELINUI/zeppelin/outbound/javascript/filter">
<content type="application/javascript">
<apply path="app/home/home.html" rule="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/home"/>
<apply path="app/notebook/notebook.html" rule="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/notebook"/>
<apply path="app/jobmanager/jobmanager.html" rule="ZEPPELINUI/zeppelin/outbound/javascript/filter/app/jobmanager"/>
</content>
</filter> |
Code Block | ||
---|---|---|
| ||
<!-- Filter -->
<route path="/zeppelin/scripts/**">
<rewrite apply="ZEPPELINUI/zeppelin/outbound/javascript/filter" to="response.body"/>
</route> |
A good example of how to use the filters is Proxying a UI using Knox.
Following are the different types of Content-Types supported by Apache Knox.
Form URL Rewrite Filter
Uses Content-Type "application/x-www-form-urlencoded", "*/x-www-form-urlencoded"
HTML URL Rewrite Filter
Uses Content-Type "application/html", "text/html", "*/html"
JavaScript URL Rewrite Filter
Uses Content-Type "application/javascript", "text/javascript", "*/javascript", "application/x-javascript", "text/x-javascript", "*/x-javascript"
JSON URL Rewrite FIlter
Uses Content-Type "application/json", "text/json", "*/json"
XML URL Rewrite FIlter
Uses Content-Type "application/xml", "text/xml", "*/xml"
Pattern Matching
Pattern matching for Knox unfortunately does not match the standard Regex format. Following is how pattern matching works in some of the cases
...