Skip to content

Commit

Permalink
#296 still hacking this idea around
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Gardham-Pallister committed Apr 15, 2018
1 parent 3ae2b28 commit c5aa11f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
21 changes: 17 additions & 4 deletions src/Ocelot/DependencyInjection/ConfigurationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,32 @@ public static IConfigurationBuilder AddOcelot(this IConfigurationBuilder builder
var reg = new Regex(pattern);

var files = Directory.GetFiles(".")
.Where(path => reg.IsMatch(path))
.Where(path => reg.IsMatch(path)).Where(x => x.Count(s => s == '.') == 3)
.ToList();

FileConfiguration ocelotConfig = new FileConfiguration();

foreach (var file in files)
{
if(files.Count > 1 && file == "./ocelot.json")
{
continue;
}

var lines = File.ReadAllText(file);
var config = JsonConvert.DeserializeObject<FileConfiguration>(lines);

if(file == "./ocelot.global.json")
{
ocelotConfig.GlobalConfiguration = config.GlobalConfiguration;
}

ocelotConfig.Aggregates.AddRange(config.Aggregates);
ocelotConfig.ReRoutes.AddRange(config.ReRoutes);
}

//var load all files with ocelot*.json
//merge these files into one
//save it as ocelot.json
var json = JsonConvert.SerializeObject(ocelotConfig);
File.WriteAllText("ocelot.json", json);
builder.AddJsonFile("ocelot.json");
return builder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ public void should_merge_files()
File.WriteAllText("ocelot.global.json", globalJson);

var reRouteJson = JsonConvert.SerializeObject(reRoute);
File.WriteAllText("ocelot.reRoute.json", reRouteJson);
File.WriteAllText("ocelot.reRoutes.json", reRouteJson);

IConfigurationBuilder builder = new ConfigurationBuilder();
builder.AddOcelot();

var configRoot = builder.Build();
}

private void GivenTheBaseUrl(string baseUrl)
Expand Down

0 comments on commit c5aa11f

Please sign in to comment.