Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tor Langlo 189 posts 532 karma points
    Nov 05, 2018 @ 16:22
    Tor Langlo
    0

    How can I specify different configuration for the back office based on cloud instance/site?

    In my back office I have a custom property editor which accesses another web site's web api. I have a need to vary the url for this other web site based on which cloud site I'm on (local, dev, or live). How can I do this?

    I have already specified the url's in my web.config, web.development.xdt.config, and web.live.xdt.config. Is there a way to transfer this information from the server side to the client side back office?

    -Tor

  • Niels Hartvig 1951 posts 2391 karma points c-trib
    Nov 05, 2018 @ 16:39
    Niels Hartvig
    0

    Hi Tor!

    Config transforms are your friend. There's documentation and videos about that feature here: https://our.umbraco.com/documentation/Umbraco-Cloud/Set-Up/Config-Transforms/

    Hope this helps!

    /n

  • Tor Langlo 189 posts 532 karma points
    Nov 05, 2018 @ 18:43
    Tor Langlo
    0

    Hi Niels,

    I've got the config transforms under control, and it's working well in the back-end of my "front-end" site. And I'm passing the config data (the url) to my client side javascript code via Razor.

    The challenge is the client-side Angular code for the back-office custom property editor. How can I replace the "domain" string literal in the code snippet below with values from web.config (or somewhere else)?

    angular.module('umbraco')
      .controller('productid.editorcontroller', function($scope, $http) {
        $scope.search = function(id) {
          var domain = 'https://www.myothersite.com';
          var url = domain + '/api/products/' + id;
          $http.get(url)
            .then(
              function onSuccess(response) {
              },
              function onError(response) {
              }
            );
        };
      });
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Nov 05, 2018 @ 19:01
    Nik
    100

    Hey Tor,

    I wrote a post about something that might help with this.

    https://www.justnik.me/blog/accessing-config-settings-in-your-umbraco-angular-controller

    Umbraco provides access to something called Umbraco.Sys.Variables in angular which you can hook into during some of the startup events. In there you can add your own behaviour and as a result you might be able to put in the base URL of your API end point. Have a read, it might help :-) You could use the premise to read the domain from an AppSetting populated by a config transform.

    Nik

  • Tor Langlo 189 posts 532 karma points
    Nov 05, 2018 @ 21:28
    Tor Langlo
    1

    Thanks Nik! I'll definitely look into this.

    -Tor

Please Sign in or register to post replies

Write your reply to:

Draft