From cefb21e6a6c84c8b6366b167be7de3ebd4cb31fb Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 May 2021 16:59:08 +0900 Subject: [PATCH 01/17] Drop /Home as root url in favor of / --- README.md | 4 ++-- src/Tippy/Pages/Home/Index.cshtml | 2 +- src/Tippy/Program.cs | 3 ++- src/Tippy/Startup.cs | 12 ++++++++++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8811387..323c4a4 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ brew install nervosnetwork/tap/tippy ### Tippy Console and UI -While Tippy runs as a console application, it also provides web UI. By default the dashboard UI will be opened automatically, if not you can access it by visiting [http://localhost:5000/Home](http://localhost:5000/Home) from a browser. +While Tippy runs as a console application, it also provides web UI. By default the dashboard UI will be opened automatically, if not you can access it by visiting [http://localhost:5000/](http://localhost:5000/) from a browser. ### Debugger @@ -462,7 +462,7 @@ Response ``` 4. Open `Tippy.sln` with Visual Studio 2019 (v16.8 or later), Visual Studio 2019 for Mac (v8.8 or later), or Visual Studio Code 5. Select `Tippy` as startup project for the solution, then start debugging it -6. Browse `http://localhost:5000/home` in your browser +6. Browse `http://localhost:5000/` in your browser ### Add Database Migration diff --git a/src/Tippy/Pages/Home/Index.cshtml b/src/Tippy/Pages/Home/Index.cshtml index bec25af..e1b1e70 100644 --- a/src/Tippy/Pages/Home/Index.cshtml +++ b/src/Tippy/Pages/Home/Index.cshtml @@ -1,4 +1,4 @@ -@page +@page "/" @using Tippy.Util @model Tippy.Pages.Home.IndexModel @{ diff --git a/src/Tippy/Program.cs b/src/Tippy/Program.cs index 5031020..24685e7 100644 --- a/src/Tippy/Program.cs +++ b/src/Tippy/Program.cs @@ -34,7 +34,8 @@ public static void Main(string[] args) Task.Run(async () => { await Task.Delay(2000); - UrlOpener.Open("http://localhost:5000/home"); + // TODO: read from hosting URLs + UrlOpener.Open("http://localhost:5000/"); }); } diff --git a/src/Tippy/Startup.cs b/src/Tippy/Startup.cs index 002842f..89ba118 100644 --- a/src/Tippy/Startup.cs +++ b/src/Tippy/Startup.cs @@ -86,6 +86,18 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) // endpoints.MapFallbackToController("Index", "Home"); }); + + app.Use(async (context,next) => + { + var url = context.Request.Path.Value ?? ""; + if (url.ToLower().EndsWith("/home")) + { + context.Response.Redirect("/"); + return; + } + + await next(); + }); } } } From e542eda06e4f2d5e326996560ccfdf9c3208d965 Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 May 2021 17:33:31 +0900 Subject: [PATCH 02/17] Open first listening address on launch --- src/Tippy/Program.cs | 13 ------------- src/Tippy/Startup.cs | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Tippy/Program.cs b/src/Tippy/Program.cs index 24685e7..cc839dd 100644 --- a/src/Tippy/Program.cs +++ b/src/Tippy/Program.cs @@ -1,15 +1,12 @@ using System; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; -using Tippy.Core; using Tippy.Ctrl; using Tippy.Hubs; -using Tippy.Util; namespace Tippy { @@ -28,16 +25,6 @@ public static void Main(string[] args) _hubContext = host.Services.GetService(typeof(IHubContext)) as IHubContext; ProcessManager.NodeLogReceived += OnNodeLogReceived; ProcessManager.FetchInfo(); - - if (Settings.GetSettings().AppSettings.OpenBrowserOnLaunch) - { - Task.Run(async () => - { - await Task.Delay(2000); - // TODO: read from hosting URLs - UrlOpener.Open("http://localhost:5000/"); - }); - } host.Run(); } diff --git a/src/Tippy/Startup.cs b/src/Tippy/Startup.cs index 89ba118..19c7b16 100644 --- a/src/Tippy/Startup.cs +++ b/src/Tippy/Startup.cs @@ -1,16 +1,21 @@ using System; using System.IO; +using System.Linq; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Server.Kestrel.Core; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Tippy.Core; using Tippy.Filters; using Tippy.Hubs; - +using Tippy.Util; +using IHostApplicationLifetime = Microsoft.Extensions.Hosting.IHostApplicationLifetime; + namespace Tippy { public class Startup @@ -56,7 +61,7 @@ public void ConfigureServices(IServiceCollection services) } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime appLifetime) { if (env.IsDevelopment()) { @@ -87,7 +92,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) // endpoints.MapFallbackToController("Index", "Home"); }); - app.Use(async (context,next) => + app.Use(async (context, next) => { var url = context.Request.Path.Value ?? ""; if (url.ToLower().EndsWith("/home")) @@ -98,6 +103,14 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) await next(); }); + + appLifetime.ApplicationStarted.Register(() => { + if (Settings.GetSettings().AppSettings.OpenBrowserOnLaunch) + { + var root = app.ServerFeatures.Get().Addresses.ToList().First(); + UrlOpener.Open(root); + } + }); } } } From 19329d458174f285d07cd25c4df38933986043ae Mon Sep 17 00:00:00 2001 From: James Chen Date: Tue, 25 May 2021 18:04:54 +0900 Subject: [PATCH 03/17] Redirect bdg/ttyd version command stdio --- src/Tippy.Ctrl/Process/BinariesInfo.cs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Tippy.Ctrl/Process/BinariesInfo.cs b/src/Tippy.Ctrl/Process/BinariesInfo.cs index a77e1f7..4189a4f 100644 --- a/src/Tippy.Ctrl/Process/BinariesInfo.cs +++ b/src/Tippy.Ctrl/Process/BinariesInfo.cs @@ -57,8 +57,17 @@ void RefreshDebuggerDeps() process.StartInfo.UseShellExecute = false; process.StartInfo.FileName = dep; process.StartInfo.Arguments = "--version"; - process.StartInfo.WorkingDirectory = Core.Environment.GetAppDataFolder(); - process.Start(); + process.StartInfo.WorkingDirectory = Core.Environment.GetAppDataFolder(); + process.StartInfo.RedirectStandardOutput = true; + process.OutputDataReceived += (sender, e) => + { + if (!String.IsNullOrEmpty(e.Data)) + { + Info += e.Data + "\n"; + } + }; + process.Start(); + process.BeginOutputReadLine(); process.WaitForExit(); } catch From a2757867b95c0abfb83801544fbf1d318fb005f3 Mon Sep 17 00:00:00 2001 From: James Chen Date: Wed, 26 May 2021 08:21:40 +0900 Subject: [PATCH 04/17] Read and use AppUrl --- src/Tippy.Core/Settings.cs | 1 + src/Tippy/Pages/Config/Index.cshtml | 6 ++++++ src/Tippy/Pages/Config/Index.cshtml.cs | 1 + src/Tippy/Pages/Home/Index.cshtml | 2 +- src/Tippy/Pages/Home/Index.cshtml.cs | 15 ++++++++++++--- src/Tippy/Properties/launchSettings.json | 2 +- src/Tippy/Startup.cs | 4 ++-- 7 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/Tippy.Core/Settings.cs b/src/Tippy.Core/Settings.cs index c0eb3d7..78e8a23 100644 --- a/src/Tippy.Core/Settings.cs +++ b/src/Tippy.Core/Settings.cs @@ -8,6 +8,7 @@ namespace Tippy.Core public class Settings { public AppSettings AppSettings { get; set; } = default!; + public string AppUrl { get; set; } = ""; private static Settings? singleton; public static Settings GetSettings() diff --git a/src/Tippy/Pages/Config/Index.cshtml b/src/Tippy/Pages/Config/Index.cshtml index 191f499..c43d288 100644 --- a/src/Tippy/Pages/Config/Index.cshtml +++ b/src/Tippy/Pages/Config/Index.cshtml @@ -27,6 +27,12 @@ +
+
+

App Url: @Model.AppUrl

+
+
+