From 50a6864c12a011accc316f335728ca949f34f6fa Mon Sep 17 00:00:00 2001 From: exyi Date: Sun, 27 Sep 2020 09:26:28 +0000 Subject: [PATCH] Switch frontend to using dotnet proxy project --- frontend/package.json | 3 ++- frontend/public/{index.html => grafik.html} | 0 server/Ksp.WebServer/Startup.cs | 15 +++++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) rename frontend/public/{index.html => grafik.html} (100%) diff --git a/frontend/package.json b/frontend/package.json index 03a7071..77a86f4 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -4,7 +4,8 @@ "scripts": { "build": "rollup -c", "dev": "rollup -c -w", - "start": "sirv public", + "start": "dotnet run --project ../server/Ksp.WebServer", + "start-sirv": "sirv public", "validate": "svelte-check" }, "devDependencies": { diff --git a/frontend/public/index.html b/frontend/public/grafik.html similarity index 100% rename from frontend/public/index.html rename to frontend/public/grafik.html diff --git a/server/Ksp.WebServer/Startup.cs b/server/Ksp.WebServer/Startup.cs index 20552e8..71cdffc 100644 --- a/server/Ksp.WebServer/Startup.cs +++ b/server/Ksp.WebServer/Startup.cs @@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Rewrite; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; @@ -64,6 +65,10 @@ namespace Ksp.WebServer endpoints.MapControllers(); }); + app.UseRewriter(new RewriteOptions() + .AddRewrite("^grafik$", "grafik.html", true) + ); + app.UseStaticFiles(new StaticFileOptions { FileProvider = new PhysicalFileProvider( Path.Combine(env.ContentRootPath, "../../frontend/public")), @@ -76,7 +81,7 @@ namespace Ksp.WebServer }, opt => { opt.WithHttpClientName("RedirectClient"); - opt.WithBeforeSend(async (cx, request) => { + opt.WithBeforeSend((cx, request) => { request.Headers.Authorization = new AuthenticationHeaderValue("Basic", "SECRET"); if (request.Headers.Referrer is object) @@ -92,10 +97,11 @@ namespace Ksp.WebServer // request.Headers.Remove("Forwarded"); // request.Headers.Remove("Origin"); // request.Headers.Add("Origin", "https://ksp-test.ks.matfyz.cz"); - Console.WriteLine(request); + // Console.WriteLine(request); + return Task.CompletedTask; }); - opt.WithAfterReceive(async (cx, response) => { - Console.WriteLine(response); + opt.WithAfterReceive((cx, response) => { + // Console.WriteLine(response); if (response.Headers.Location is object && response.Headers.Location.Host == "ksp-test.ks.matfyz.cz") { response.Headers.Location = new UriBuilder(response.Headers.Location) { @@ -112,6 +118,7 @@ namespace Ksp.WebServer .Replace("; domain=ksp-test.ks.matfyz.cz", $"; domain={cx.Request.Host.Host}") )); } + return Task.CompletedTask; }); })); }