DiamondLightSource/SynchWeb

Incorrect client/src/index.php HtmlWebpackPlugin template

Closed this issue · 2 comments

It is my understanding that HtmlWebpackPlugin is used at build time to generate client/index.php from client/src/index.php. If I'm understanding this correctly, then it looks like the HtmlWebpackPlugin template in client/src/index.php is wrong in that it uses the "evaluate" delimiter <% in some places which results in evaluation at build time but not at run time. For example, if ga_ident is not the empty string at build time, the Google Analytics functionality will always be active even if ga_ident is later changed at run time to the empty string in the client's config:

<% if (htmlWebpackPlugin.options.jsonConfig.ga_ident) { %>
<script type="text/javascript">
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
 
  ga('create', '<%= htmlWebpackPlugin.options.jsonConfig.ga_ident %>', 'auto');
  ga('send', 'pageview');
</script>
<% } %>

Similarly, if the client config has a maintenance message enabled at build time, it will always be enabled with no way to disable it at run time:

<% if ( htmlWebpackPlugin.options.jsonConfig.maintenance ) { %>
    <a class="icon"><i class="fa fa-2x fa-home"></i>&nbsp;</a>
<% } %>

and:

<% if ( htmlWebpackPlugin.options.jsonConfig.maintenance ) { %>
    <h1>Scheduled Maintenance</h1>
    <p><%= htmlWebpackPlugin.options.jsonConfig.maintenance_message %></p>
    <br />
<% } %>

Hi. At the moment this is by design. The Google analytics property is something we set for production builds but not on our staging servers. Our ansible deployment scripts generate the config.json properties as part of the build process. So I don't think we would ever want this to be dynamic. Really the values in this config file are build settings rather than runtime settings. The exceptions are build hash (used to refresh long running sessions after a new build), client and app urls.

The maintenance flag could be changed to be dynamic. It would help in some cases where you need to quickly change the server to stop processing requests. However, it followed the same pattern as GA because it was the simplest way to get the same behaviour pre-webpack. Its a js config file setting that changes behaviour of the backend php! I think in most cases though we would have planned maintenance and so the current process works. Moving forward separating truly runtime settings from build settings would make sense.

OK, thanks for the explanation. Closing this issue.