From 68d256caf002ef2d08529a66dc30da69176a2199 Mon Sep 17 00:00:00 2001 From: SpringHgui <740360381@qq.com> Date: Sat, 31 Oct 2020 00:04:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0webapi?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastTunnel.Core/FastTunnel.Core.csproj | 1 + .../WebApi/Controllers/HomeController.cs | 16 ++++++ FastTunnel.Server/Program.cs | 3 ++ .../Properties/launchSettings.json | 22 +++++++- FastTunnel.Server/Startup.cs | 52 +++++++++++++++++++ 5 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 FastTunnel.Core/WebApi/Controllers/HomeController.cs create mode 100644 FastTunnel.Server/Startup.cs diff --git a/FastTunnel.Core/FastTunnel.Core.csproj b/FastTunnel.Core/FastTunnel.Core.csproj index 2700130..982b2a8 100644 --- a/FastTunnel.Core/FastTunnel.Core.csproj +++ b/FastTunnel.Core/FastTunnel.Core.csproj @@ -31,6 +31,7 @@ + diff --git a/FastTunnel.Core/WebApi/Controllers/HomeController.cs b/FastTunnel.Core/WebApi/Controllers/HomeController.cs new file mode 100644 index 0000000..33c3e4e --- /dev/null +++ b/FastTunnel.Core/WebApi/Controllers/HomeController.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +namespace FastTunnel.Core.WebApi.Controllers +{ + public class HomeController : Controller + { + public string Index() + { + return "ok"; + } + } +} diff --git a/FastTunnel.Server/Program.cs b/FastTunnel.Server/Program.cs index 674612d..7090eb4 100644 --- a/FastTunnel.Server/Program.cs +++ b/FastTunnel.Server/Program.cs @@ -33,6 +33,9 @@ namespace FastTunnel.Server // DI services.AddTransient(); //services.AddSingleton(); + }).ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); }); } } diff --git a/FastTunnel.Server/Properties/launchSettings.json b/FastTunnel.Server/Properties/launchSettings.json index 7a6b163..5a6f375 100644 --- a/FastTunnel.Server/Properties/launchSettings.json +++ b/FastTunnel.Server/Properties/launchSettings.json @@ -1,7 +1,27 @@ { + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:5249", + "sslPort": 0 + } + }, "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, "FastTunnel.Server": { - "commandName": "Project" + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" }, "Docker": { "commandName": "Docker" diff --git a/FastTunnel.Server/Startup.cs b/FastTunnel.Server/Startup.cs new file mode 100644 index 0000000..70f079c --- /dev/null +++ b/FastTunnel.Server/Startup.cs @@ -0,0 +1,52 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace FastTunnel.Server +{ + public class Startup + { + public IConfiguration Configuration { get; } + + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public void ConfigureServices(IServiceCollection services) + { + services.AddControllersWithViews(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Home/Error"); + + // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. + app.UseHsts(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllerRoute( + name: "default", + pattern: "{controller=Home}/{action=Index}/{id?}"); + }); + } + } +} \ No newline at end of file