aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-23 21:15:25 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-23 21:15:25 -0600
commit01b69a964a5162b5fcbf91774ee39d8a4e429dd6 (patch)
tree7a2e9eb0a2a3d3925c3239cf74e9de9a092b3386 /src/slskd
parentbd9a001270987265f0615909ec54fdb0e8b87b62 (diff)
downloadslskd-01b69a964a5162b5fcbf91774ee39d8a4e429dd6.tar.gz
adjust options
Diffstat (limited to 'src/slskd')
-rw-r--r--src/slskd/Startup.cs28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index 83f2cb71..eb9c8bed 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -45,6 +45,9 @@
private SoulseekClient Client { get; set; }
private object ConsoleSyncRoot { get; } = new object();
private ISharedFileCache SharedFileCache { get; set; }
+ private string UrlBase { get; set; }
+ private string ContentPath { get; set; }
+ private SymmetricSecurityKey JwtSigningKey { get; set; }
public Startup(IConfiguration configuration)
{
@@ -71,14 +74,19 @@
services.AddOptions<Configuration.Authentication>()
.Bind(Configuration.GetSection("authentication"));
+ UrlBase = Program.Options.Web.UrlBase;
+ UrlBase = UrlBase.StartsWith("/") ? UrlBase : "/" + UrlBase;
+
+ ContentPath = Path.GetFullPath(Program.Options.Web.ContentPath);
+
+ JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Program.Options.Web.Jwt.Key));
+
services.AddCors(options => options.AddPolicy("AllowAll", builder => builder.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader()));
+ services.AddSingleton(JwtSigningKey);
+
if (!Program.Options.NoAuth)
{
- var jwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Program.Options.Web.Jwt.Key));
-
- services.AddSingleton(jwtSigningKey);
-
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
@@ -91,7 +99,7 @@
ValidIssuer = "slskd",
ValidateIssuer = true,
ValidateAudience = false,
- IssuerSigningKey = jwtSigningKey,
+ IssuerSigningKey = JwtSigningKey,
ValidateIssuerSigningKey = true,
};
});
@@ -193,22 +201,22 @@
FileServerOptions fileServerOptions = default;
- if (!System.IO.Directory.Exists(Program.Options.Web.ContentPath))
+ if (!System.IO.Directory.Exists(ContentPath))
{
- logger.Warning($"Static content disabled; cannot find content path '{Program.Options.Web.ContentPath}'");
+ logger.Warning($"Static content disabled; cannot find content path '{ContentPath}'");
}
else
{
fileServerOptions = new FileServerOptions
{
- FileProvider = new PhysicalFileProvider(Program.Options.Web.ContentPath),
+ FileProvider = new PhysicalFileProvider(ContentPath),
RequestPath = "",
EnableDirectoryBrowsing = false,
EnableDefaultFiles = true
};
app.UseFileServer(fileServerOptions);
- logger.Information("Serving static content from {ContentPath}", Program.Options.Web.ContentPath);
+ logger.Information("Serving static content from {ContentPath}", ContentPath);
}
app.UseSerilogRequestLogging();
@@ -254,7 +262,7 @@
// finally, hit the fileserver again. if the path was modified to return the index above, the index document will be returned
// otherwise it will throw a final 404 back to the client.
- if (System.IO.Directory.Exists(Program.Options.Web.ContentPath))
+ if (System.IO.Directory.Exists(ContentPath))
{
app.UseFileServer(fileServerOptions);
}