Skip to content

Commit

Permalink
Added Cors Allowed Origins logging
Browse files Browse the repository at this point in the history
  • Loading branch information
DAQEM committed Jan 12, 2024
1 parent 75c03a3 commit de20296
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Services/AdminWebApp/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const config = {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
adapter: adapter(),
csrf: {
checkOrigin: false
}
}
};

Expand Down
20 changes: 19 additions & 1 deletion Services/Netmon.DeviceManager/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,25 @@
Console.WriteLine("Unable to start polling job (probably because it cannot connect to the database): {0}", e.Message);
}


try
{
ILogger<Program> logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
string[]? allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get<string[]>();
if (allowedOrigins is null)
{
logger.LogWarning("No allowed origins specified, CORS will not be enabled");
}
else
{
logger.LogInformation("Environment Variables: {EnvironmentVariables}", string.Join(", ", Environment.GetEnvironmentVariables().Keys.Cast<string>()));
logger.LogInformation("Allowed Origins: {AllowedOrigins}", string.Join(", ", allowedOrigins));
}
}
catch (InvalidOperationException e)
{
Console.WriteLine("Unable to get logger: {0}", e.Message);
}

}

app.Run();
22 changes: 20 additions & 2 deletions Services/Netmon.SNMPPolling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,34 @@
app.UseMiddleware<ExceptionMiddleware>();
}

using (IServiceScope serviceScope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
using (IServiceScope scope = app.Services.GetRequiredService<IServiceScopeFactory>().CreateScope())
{
DevicesDatabase? context = serviceScope.ServiceProvider.GetService<DevicesDatabase>();
DevicesDatabase? context = scope.ServiceProvider.GetService<DevicesDatabase>();
try
{
context?.Database.EnsureCreated();
}
catch (MySqlException)
{
}

try
{
ILogger<Program> logger = scope.ServiceProvider.GetRequiredService<ILogger<Program>>();
string[]? allowedOrigins = builder.Configuration.GetSection("Cors:AllowedOrigins").Get<string[]>();
if (allowedOrigins is null)
{
logger.LogWarning("No allowed origins specified, CORS will not be enabled");
}
else
{
logger.LogInformation("Allowed Origins: {AllowedOrigins}", string.Join(", ", allowedOrigins));
}
}
catch (InvalidOperationException e)
{
Console.WriteLine("Unable to get logger: {0}", e.Message);
}
}

app.Run();
Expand Down
5 changes: 4 additions & 1 deletion Services/UserWebApp/svelte.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ const config = {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list.
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
adapter: adapter(),
csrf: {
checkOrigin: false
}
}
};

Expand Down

0 comments on commit de20296

Please sign in to comment.