Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gfs committed Feb 4, 2020
2 parents 1f1afb6 + f298726 commit 444da02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Asa/Program.cs
Expand Up @@ -18,6 +18,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
Expand Down Expand Up @@ -78,6 +79,9 @@ private static int RunGuiCommand(GuiCommandOptions opts)

WebHost.CreateDefaultBuilder(Array.Empty<string>())
.UseStartup<Asa.Startup>()
.UseKestrel(options => {
options.Listen(IPAddress.Loopback, 5000); //HTTP port
})
.Build()
.Run();

Expand Down
26 changes: 24 additions & 2 deletions Asa/Startup.cs
@@ -1,8 +1,14 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Serilog;
using System;
using System.IO;
using System.Reflection;

namespace Asa
{
Expand Down Expand Up @@ -34,11 +40,27 @@ public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseExceptionHandler("/Home/Error");
}
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Path.Combine(Path.GetDirectoryName(Uri.UnescapeDataString(uri.Path)),"wwwroot");

try
{
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(path),
RequestPath = new PathString("")
});
}
catch(Exception e)
{
Log.Debug("Had an issue setting static file path. Reverting to default.");
app.UseStaticFiles();
}


app.UseEndpoints(endpoints =>
{
Expand Down

0 comments on commit 444da02

Please sign in to comment.