Skip to content

Commit

Permalink
Replace NETHERMIND_CORS_ORIGINS with IJsonRpc.CorsOrigins
Browse files Browse the repository at this point in the history
  • Loading branch information
rubo committed Oct 31, 2024
1 parent 29368c8 commit 22d36b7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public void NoCategorySettings()
{ "NETHERMIND_CLI_SWITCH_LOCAL", "http://localhost:80" },
{ "NETHERMIND_MONITORING_JOB", "nethermindJob" },
{ "NETHERMIND_MONITORING_GROUP", "nethermindGroup" },
{ "NETHERMIND_CORS_ORIGINS", "*" },
{ "NETHERMIND_CONFIG", "test2.json" },
{ "NETHERMIND_XYZ", "xyz" }, // not existing, should get error
{ "QWER", "qwerty" } // not Nethermind setting, no error
Expand Down
3 changes: 0 additions & 3 deletions src/Nethermind/Nethermind.Config/INoCategoryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public interface INoCategoryConfig : IConfig
[ConfigItem(Description = "Sets the default group name for metrics monitoring.", EnvironmentVariable = "NETHERMIND_MONITORING_GROUP")]
public string MonitoringGroup { get; set; }

[ConfigItem(Description = "Defines CORS origins for JSON RPC.", DefaultValue = "*", EnvironmentVariable = "NETHERMIND_CORS_ORIGINS")]
public string CorsOrigins { get; set; }

[ConfigItem(Description = "Defines host value for CLI function \"switchLocal\".", DefaultValue = "http://localhost", EnvironmentVariable = "NETHERMIND_CLI_SWITCH_LOCAL")]
public string CliSwitchLocal { get; set; }
}
1 change: 0 additions & 1 deletion src/Nethermind/Nethermind.Config/NoCategoryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ public class NoCategoryConfig : INoCategoryConfig
public string Config { get; set; } = null;
public string MonitoringJob { get; set; }
public string MonitoringGroup { get; set; }
public string CorsOrigins { get; set; }
public string CliSwitchLocal { get; set; }
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc/IJsonRpcConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,7 @@ public interface IJsonRpcConfig : IConfig

[ConfigItem(Description = "The error margin used in the `eth_estimateGas` JSON-RPC method, in basis points.", DefaultValue = "150")]
int EstimateErrorMargin { get; set; }

[ConfigItem(Description = "The JSON-RPC server CORS origins.", DefaultValue = "*")]
string[] CorsOrigins { get; set; }
}
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using Nethermind.Core.Extensions;
using Nethermind.JsonRpc.Modules;
Expand Down Expand Up @@ -57,6 +58,7 @@ public int WebSocketsPort
public long? MaxBatchResponseBodySize { get; set; } = 32.MiB();
public long? MaxSimulateBlocksCap { get; set; } = 256;
public int EstimateErrorMargin { get; set; } = 150;
public string[] CorsOrigins { get; set; } = ["*"];
};
};

10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Runner/JsonRpc/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
using Nethermind.Api;
using Nethermind.Config;
using Nethermind.Core.Authentication;
using Nethermind.Core.Extensions;
using Nethermind.Core.Resettables;
using Nethermind.HealthChecks;
using Nethermind.JsonRpc;
Expand Down Expand Up @@ -57,9 +56,10 @@ public void ConfigureServices(IServiceCollection services)
});
Bootstrap.Instance.RegisterJsonRpcServices(services);

string corsOrigins = Environment.GetEnvironmentVariable("NETHERMIND_CORS_ORIGINS") ?? "*";
services.AddCors(c => c.AddPolicy("Cors",
p => p.AllowAnyMethod().AllowAnyHeader().WithOrigins(corsOrigins)));
services.AddCors(options => options.AddDefaultPolicy(builder => builder
.AllowAnyMethod()
.AllowAnyHeader()
.WithOrigins(jsonRpcConfig.CorsOrigins)));

services.AddResponseCompression(options =>
{
Expand All @@ -79,8 +79,8 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IJsonRpc
app.UseDeveloperExceptionPage();
}

app.UseCors("Cors");
app.UseRouting();
app.UseCors();
app.UseResponseCompression();

IConfigProvider? configProvider = app.ApplicationServices.GetService<IConfigProvider>();
Expand Down

0 comments on commit 22d36b7

Please sign in to comment.