Exemple #1
0
        private static void SetupSpaRuntimeConfig(IConfiguration configuration)
        {
            var spaOptions    = configuration.GetSection(nameof(SpaOptions)).Get <SpaOptions>();
            var runtimeConfig = new SpaRuntimeConfig(spaOptions);

            TryOverrideRuntimeConfig(runtimeConfig, $@"{spaOptions.SourcePath}/public/index.html");
            TryOverrideRuntimeConfig(runtimeConfig, $@"{spaOptions.SourcePath}/build/index.html");
        }
Exemple #2
0
        private static void TryOverrideRuntimeConfig(SpaRuntimeConfig runtimeConfig, string path)
        {
            if (File.Exists(path))
            {
                var configContent = "";
                foreach (var propertyInfo in runtimeConfig.GetType().GetProperties())
                {
                    configContent += $"{propertyInfo.Name}:\'{propertyInfo.GetValue(runtimeConfig)}\',";
                }

                var indexHtml = File.ReadAllText(path);
                indexHtml = Regex.Replace(indexHtml,
                                          @"window\.runConfig\s?=\s?{(.|\n)*?}",
                                          $"window.runConfig={{{configContent}}}");

                File.WriteAllText(path, indexHtml);
            }
        }