Generating the correct URL for service models

Change-Id: I2b004176b74043f46ee96b0bad4f0659422836da
diff --git a/conf/browsersync.conf.js b/conf/browsersync.conf.js
index d820bb6..391f688 100644
--- a/conf/browsersync.conf.js
+++ b/conf/browsersync.conf.js
@@ -10,12 +10,12 @@
         conf.paths.src
       ],
       middleware: function(req, res, next){
-        if (req.url.indexOf('xosapi') !== -1) {
+        if (req.url.indexOf('xosapi') !== -1 || req.url.indexOf('socket.io') !== -1) {
           proxy.web(req, res);
         }
-        // else if (req.url.indexOf('extensions') !== -1) {
-        //   extensionsProxy.web(req, res);
-        // }
+        else if (req.url.indexOf('extensions') !== -1) {
+          extensionsProxy.web(req, res);
+        }
         else{
           next();
         }
diff --git a/conf/proxy.js b/conf/proxy.js
index fedbf72..d2459d8 100644
--- a/conf/proxy.js
+++ b/conf/proxy.js
@@ -1,11 +1,13 @@
 const httpProxy = require('http-proxy');
 
+const target = process.env.PROXY || '192.168.46.100';
+
 const proxy = httpProxy.createProxyServer({
-  target: 'http://192.168.46.100:9101'
+  target: `http://${target}:9101`
 });
 
 const extensionsProxy = httpProxy.createProxyServer({
-  target: 'http://192.168.46.100/spa/'
+  target: `http://${target}/spa/`
 });
 
 proxy.on('error', function(error, req, res) {
diff --git a/src/app/core/services/helpers/config.helpers.ts b/src/app/core/services/helpers/config.helpers.ts
index 0ec20cd..241d380 100644
--- a/src/app/core/services/helpers/config.helpers.ts
+++ b/src/app/core/services/helpers/config.helpers.ts
@@ -275,7 +275,7 @@
 
       item.$save()
         .then((res) => {
-          if (res.status === 403 || res.status === 405 || res.status === 500) {
+          if (res.status === 403 || res.status === 405 || res.status === 404 || res.status === 500) {
             // TODO understand why 405 does not go directly in catch (it may be related to ng-rest-gw)
             throw new Error();
           }
diff --git a/src/app/datasources/helpers/model-discoverer.service.ts b/src/app/datasources/helpers/model-discoverer.service.ts
index b1382bd..1078853 100644
--- a/src/app/datasources/helpers/model-discoverer.service.ts
+++ b/src/app/datasources/helpers/model-discoverer.service.ts
@@ -24,6 +24,7 @@
 export interface IXosModelDiscovererService {
   discover(): ng.IPromise<boolean>;
   get(modelName: string): IXosModel;
+  getApiUrlFromModel(model: IXosModel): string;
 }
 
 export class XosModelDiscovererService implements IXosModelDiscovererService {
@@ -59,6 +60,16 @@
     return _.find(this.xosModels, m => m.name === modelName);
   }
 
+  public getApiUrlFromModel(model: IXosModel): string {
+    if (model.app === 'core') {
+      return `/core/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
+    }
+    else {
+      const serviceName = this.serviceNameFromAppName(model.app);
+      return `/${serviceName}/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
+    }
+  }
+
   public discover() {
     const d = this.$q.defer();
     this.progressBar.start();
@@ -133,16 +144,6 @@
     return parentState;
   }
 
-  private getApiUrlFromModel(model: IXosModel): string {
-    if (model.app === 'core') {
-      return `/core/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
-    }
-    else {
-      const serviceName = this.serviceNameFromAppName(model.app);
-      return `/${serviceName}/${this.ConfigHelpers.pluralize(model.name.toLowerCase())}`;
-    }
-  }
-
   // add a service state and navigation item if it is not already there
   private addService(model: IXosModel): string {
     const serviceName: string = this.serviceNameFromAppName(model.app);
diff --git a/src/app/views/crud/crud.ts b/src/app/views/crud/crud.ts
index 6b30edc..90d3342 100644
--- a/src/app/views/crud/crud.ts
+++ b/src/app/views/crud/crud.ts
@@ -89,8 +89,7 @@
       // if it is the create page
       if ($stateParams['id'] === 'add') {
         // generate a resource for an empty model
-        // TODO get the proper URL from model discoverer
-        const endpoint = this.StoreHelpers.urlFromCoreModel(this.data.model);
+        const endpoint = this.XosModelDiscovererService.getApiUrlFromModel(this.XosModelDiscovererService.get(this.data.model));
         const resource = this.ModelRest.getResource(endpoint);
         this.model = new resource({});
       }
@@ -110,4 +109,3 @@
   controllerAs: 'vm',
   controller: CrudController
 };
-