Copied to clipboard

Flag this post as spam?

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


  • Anthony Powell 13 posts 47 karma points
    Apr 21, 2021 @ 23:46
    Anthony Powell
    0

    Umbraco Package Custom Environment Variables

    Hi,

    I'm searching around but have not been able to see a straight forward way of managing environment variables in a Umbraco Custom Packages.

    Normally I would use Octopus Deploy Variables Substitution to swap out a token upon deployment. This is quite straight forward normally. So I don't feel I should have to write custom code to resolve this issue. So this is why I'm asking here.

    I have created a backoffice package for displaying an author wiki as a dashboard. This dashboard is visible for all authors, but only the web administrator can edit the wiki. This wiki is just to explain common processes within the site. Below is what all users will see.

    (Authors View) enter image description here

    I have configured this second website's hosting and culture to receive requests for localhost:2 (Simplified for this). I've also restricted the editing access to just be the web administrator user group.

    (Web Admin View) enter image description here

    So under the hood, the wiki daskboard is just an iFrame pointing to the second hosted site that the web admin manages. So I need to change that iFrame URL per-environment. I have a test, staging, and production setup and Octopus deploy is managing the deployments.

    I want to be able to get an environment configuration variable to hold the wiki hosted domain. You can see my problem in this code. The localhost domain is hardcoded at the moment.

    I could simply add the html containing the iframe to Octopus's watch list, and throw a little replacement token in there e.g #{wiki-domain}.. But that is hacky, and would break the local dev environment.

    enter image description here

    So my question is, what is the best practice for managing environment variables within a custom Umbraco package?

    Note I do have a angularJs controller there ready if there is an angular service I've missed.

  • Anthony Powell 13 posts 47 karma points
    Apr 23, 2021 @ 05:26
    Anthony Powell
    0

    After waiting a day for a response. I decided to do it the only clean way I could see. I created a controller in the plugin that would look at the web.config appsettings.

    enter image description here

    The API controller simply returns the configuration back to the angularJs backoffice controller.

    Then I used that data to set the domain on the iFrame mentioned above.

    Then I created a transform on the web.config and set the "Wiki.Domain" key to be a octopus variable substitution token. '#{Wiki.Domain}. Now Octopus can manage the environment variables in the appropriate place upon deployment.

    Web.Release.config enter image description here

    Ideally I thought there would be a pre-existing Umbraco service in angularJs that already presented the app settings. Or there would be a way of adding variables in the manifest.

Please Sign in or register to post replies

Write your reply to:

Draft