mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-16 08:25:28 +00:00
Fix ASF trying to create www folder if it doesn't exist yet
It seems that ASP.NET is trying to create initialized WebRootPath if it doesn't exist yet. This might be unwanted, as user might want to explicitly disable www directory while still having interest in IPC. On top of that, ASF will outright crash if creating such directory will be impossible, e.g. because of insufficient permission. It makes sense for us to check first if the directory exists - if not, we can omit it entirely, so ASP.NET will default to NullFileProvider and simply respond 404 to everything unhandled from the code perspective. @SuperSandro2000 will resolve https://github.com/NixOS/nixpkgs/issues/312242 without a need of disabling IPC. In other words, you can use IPC with no www folder attached in order to still have ASF API and /swagger available. ASF will no longer crash in this scenario, it also won't try to create a directory on read-only filesystem.
This commit is contained in:
@@ -435,15 +435,22 @@ internal static class ArchiKestrel {
|
||||
}
|
||||
|
||||
private static async Task<WebApplication> CreateWebApplication() {
|
||||
string customDirectory = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.WebsiteDirectory);
|
||||
string websiteDirectory = Directory.Exists(customDirectory) ? customDirectory : Path.Combine(AppContext.BaseDirectory, SharedInfo.WebsiteDirectory);
|
||||
string? webRootPath = Path.Combine(Directory.GetCurrentDirectory(), SharedInfo.WebsiteDirectory);
|
||||
|
||||
if (!Directory.Exists(webRootPath)) {
|
||||
webRootPath = Path.Combine(AppContext.BaseDirectory, SharedInfo.WebsiteDirectory);
|
||||
|
||||
if (!Directory.Exists(webRootPath)) {
|
||||
webRootPath = null;
|
||||
}
|
||||
}
|
||||
|
||||
// The order of dependency injection matters, pay attention to it
|
||||
WebApplicationBuilder builder = WebApplication.CreateEmptyBuilder(
|
||||
new WebApplicationOptions {
|
||||
ApplicationName = SharedInfo.AssemblyName,
|
||||
ContentRootPath = SharedInfo.HomeDirectory,
|
||||
WebRootPath = websiteDirectory
|
||||
WebRootPath = webRootPath
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user