-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
46 lines (34 loc) · 1.54 KB
/
Copy pathProgram.cs
File metadata and controls
46 lines (34 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using TestProject.Services;
namespace TestProject {
public class Program {
/// <summary>Starts the file browser web application.</summary>
/// <param name="args">Command-line arguments supplied by the host.</param>
public static void Main(string[] args) {
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
// Add services to the container.
string configuredHomeDirectory = builder.Configuration["FileBrowser:HomeDirectory"]
?? throw new InvalidOperationException(
"FileBrowser:HomeDirectory is not configured."
);
// Combines the project root path with the given relative path
string homeDirectory = Path.IsPathRooted(configuredHomeDirectory)
? configuredHomeDirectory
: Path.Combine(
builder.Environment.ContentRootPath,
configuredHomeDirectory
);
builder.Services.AddScoped<FileService>(_ =>
{
return new FileService(homeDirectory);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseDefaultFiles();
app.UseStaticFiles();
app.MapControllers();
app.Run();
}
}
}