Add basic setup for static files

This commit is contained in:
Daniel_I_Am 2020-08-23 16:49:57 +02:00
parent 4f4075c8f4
commit b6fc17b48b
No known key found for this signature in database
GPG Key ID: 80C428FCC9743E84
4 changed files with 30 additions and 4 deletions

View File

@ -23,13 +23,14 @@
</ItemGroup>
<ItemGroup>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Folder Include="WebServer\App" />
<Folder Include="wwwroot\src" />
</ItemGroup>
</Project>

View File

@ -1,3 +1,4 @@
using System.IO;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
@ -36,7 +37,6 @@ namespace ChaosBot.WebServer
{
_logger.Info("Initializing Kestrel Startup and Configuration");
if (Program.AppSettingsHandler.GetValue<bool>("WebServer:Debug", false))
app.UseDeveloperExceptionPage();
@ -45,6 +45,12 @@ namespace ChaosBot.WebServer
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
DefaultFilesOptions options = new DefaultFilesOptions();
options.DefaultFileNames.Clear();
options.DefaultFileNames.Add("index.html");
app.UseDefaultFiles(options);
app.UseStaticFiles();
}
}
}

View File

@ -1,3 +1,4 @@
using System.IO;
using System.Net;
using NLog.Extensions.Logging;
@ -19,6 +20,11 @@ namespace ChaosBot.WebServer
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
string contentRoot = Directory.GetCurrentDirectory();
string webRoot = Path.Combine(contentRoot, "wwwroot");
webBuilder.UseContentRoot(contentRoot);
webBuilder.UseWebRoot(webRoot);
webBuilder.ConfigureKestrel(serverOptions =>
{
serverOptions.Listen(IPAddress.Any, Program.AppSettingsHandler.GetValue<int>("WebServer:Port"),

View File

@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<h2>Index</h2>
</body>
</html>