/**
 * Created by vedi on 01/02/16.
 */
module.exports = function (self) {
  return function (options) {

    // extracts the part after first subdomain
    var regexp = new RegExp('^' + options.prefix + '\.(.*$)', 'i');

    return function (req, res, next) {
      var host = req.get('host');

      var found = host.match(regexp);

      if (found) {
        var whitelabelDomain = found[1];

        var urlPrefix = self.forceSSL ? 'https://' : 'http://';

        req.whitelabel = {
          domain: whitelabelDomain,
          cookieDomain: '.' + whitelabelDomain,
          getApiUrl: function () {
            return urlPrefix + options.apiPrefix + this.cookieDomain;
          },
          getLoginUrl: function () {
            return urlPrefix + options.loginPrefix + this.cookieDomain;
          },
          getLoginUrlWithAuth: function () {
            return urlPrefix + options.loginUsername + ':' + options.loginPassword + '@' +
              options.loginPrefix + this.cookieDomain;
          },
          getEditorUrl: function () {
            return urlPrefix + options.editorPrefix + this.cookieDomain;
          },
          getProjectsUrl: function () {
            return urlPrefix + options.projectsPrefix + this.cookieDomain;
          }
        };
      }

      next();
    }
  }
};
@@ -99,16 +99,81 @@
 ons) %7B%0A%0A
+    options.backendPrefix = options.backendPrefix %7C%7C 'backend';%0A%0A
     // e
@@ -211,16 +211,16 @@
 bdomain%0A
-
     var 
@@ -392,17 +392,23 @@
 egexp);%0A
+      
 %0A
-
       if
@@ -580,32 +580,32 @@
 itelabelDomain,%0A
-
           cookie
@@ -628,32 +628,158 @@
 itelabelDomain,%0A
+          getBackendUrl: function () %7B%0A            return urlPrefix + options.backendPrefix + this.cookieDomain;%0A          %7D,%0A
           getApi

add backend resolver