...
Code Block |
---|
git clone https://github.com/angularsumitg/angular2-quickstart.git my-proj cd my-proj npm install npm start |
...
<GATEWAY_HOME>/data/services
directory you will need to create a parent and child directory exampleexampleui/0.0.1
. As a convention the names of these directories duplicate the values in the attributes of the root element of the contained service.xml.Create the two files with the content shown below and place them in the directories indicated. The links also provide the files for your convenience.
Code Block |
---|
<service role="EXAMPLEUI" name="exampleui" version="0.0.1"> <policies> <policy role="webappsec"/> <policy role="authentication" name="Anonymous"/> <policy role="rewrite"/> <policy role="authorization"/> </policies> <routes> <route path="/example"> </route> <route path="/example/**"> </route> </routes> <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/> </service> |
Code Block |
---|
<rules> <rule dir="IN" name="EXAMPLEUI/exampleui/inbound/root" pattern="*://*:*/**/example/"> <rewrite template="{$serviceUrl[EXAMPLEUI]}/"/> </rule> <rule dir="IN" name="EXAMPLEUI/exampleui/inbound/path" pattern="*://*:*/**/example/{**}"> <rewrite template="{$serviceUrl[EXAMPLEUI]}/{**}"/> </rule> </rules> |
Once that is complete, the topology file must be updated to activate this new service in the runtime. In this case the sandbox.xml topology file is used but you may have another topology file such as default.xml. Edit which ever topology file you prefer and add the… markup shown below. If you aren’t using sandbox.xml be careful to replace sandbox with the name of your topology file through these examples.
<GATEWAY_HOME>/conf/topologies/sandbox.xml
Code Block |
---|
<topology> ... <service> <role>EXAMPLEUI</role> <url>http://localhost:3000</url> </service> </topology> |
With all of these changes made you must restart your Knox gateway server. Often times this isn’t necessary but adding a new service definition under [<GATEWAY_HOME>/data/services requires restart.
...
Code Block |
---|
<topology><service><url>http://localhost:3000 |
- This populates the data used by {$serviceUrl[EXAMPLEUI]} in the rules with the correct target URL.
Taking care of slash’ness
Code Block |
---|
<link rel="stylesheet" href="styles.css"> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> |
new rewrite.xml rules
Code Block |
---|
<rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/systemjs" pattern = "systemjs.config.js"> <rewrite template="{$frontend[path]}/example/systemjs.config.js"/> </rule> <rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/styles" pattern="styles.css"> <rewrite template="{$frontend[path]}/example/styles.css"/> </rule> <rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/nodemodules" pattern="node_modules/{**}"> <rewrite template="{$frontend[path]}/example/node_modules/{**}"/> </rule> |
Code Block |
---|
<link rel="stylesheet" href="/gateway/sandbox/example/styles.css"> <!-- Polyfill(s) for older browsers --> <script src="/gateway/sandbox/example/node_modules/core-js/client/shim.min.js"></script> <script src="/gateway/sandbox/example/node_modules/zone.js/dist/zone.js"></script> <script src="/gateway/sandbox/example/node_modules/reflect-metadata/Reflect.js"></script> <script src="/gateway/sandbox/example/node_modules/systemjs/dist/system.src.js"></script> <script src="/gateway/sandbox/example/systemjs.config.js"></script> |
Code Block |
---|
... System.config({ paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { // our app is within the apps folder app: 'apps', ... |
Final rewrite.xml changes
Code Block |
---|
<rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/apps"> <rewrite template="example/apps"/> </rule> <rule dir="OUT" name="EXAMPLEUI/exampleui/outbound/nodemodule"> <rewrite template="example/node_modules"/> </rule> <filter name="EXAMPLEUI/exampleui/outbound/app"> <content type="application/javascript"> <apply path="apps" rule="EXAMPLEUI/exampleui/outbound/apps"/> <apply path="node_modules" rule="EXAMPLEUI/exampleui/outbound/nodemodule"/> </content> </filter> |
Tying it back to service.xml
Code Block |
---|
<service role="EXAMPLEUI" name="exampleui" version="0.0.1"> <policies> <policy role="webappsec"/> <policy role="authentication" name="Anonymous"/> <policy role="rewrite"/> <policy role="authorization"/> </policies> <routes> <route path="/example"> </route> <route path="/example/**"> <rewrite apply="EXAMPLEUI/exampleui/outbound/app" to="response.body"/> </route> </routes> <dispatch classname="org.apache.hadoop.gateway.dispatch.PassAllHeadersDispatch"/> </service> |
Code Block |
---|
... System.config({ paths: { // paths serve as alias 'npm:': 'example/node_modules/' }, // map tells the System loader where to look for things map: { // our app is within the example/apps folder app: 'example/apps', ... |
...