Commit eccf5894 by artur.rachwal

pi web server works

parent 104b8292
...@@ -15,5 +15,15 @@ namespace Pi.Hub.Api.Controllers ...@@ -15,5 +15,15 @@ namespace Pi.Hub.Api.Controllers
{ {
return new { Now = DateTime.Now.ToString("F") }; return new { Now = DateTime.Now.ToString("F") };
} }
[HttpPost]
[Route("[action]")]
public object Echo([FromBody]object obj)
{
return new
{
Echo = obj
};
}
} }
} }
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
<RuntimeIdentifiers>win-arm;linux-arm;x86</RuntimeIdentifiers>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Folder Include="wwwroot\" /> <Folder Include="wwwroot\" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
......
...@@ -2,8 +2,10 @@ ...@@ -2,8 +2,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
namespace Pi.Hub.Api namespace Pi.Hub.Api
...@@ -12,15 +14,14 @@ namespace Pi.Hub.Api ...@@ -12,15 +14,14 @@ namespace Pi.Hub.Api
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
var host = new WebHostBuilder() BuildWebHost(args).Run();
.UseKestrel() }
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration() public static IWebHost BuildWebHost(string[] args) =>
WebHost
.CreateDefaultBuilder(args)
.UseStartup<Startup>() .UseStartup<Startup>()
.UseApplicationInsights() .UseKestrel(opt => opt.Listen(IPAddress.Parse("169.254.25.213"), 5000))
.Build(); .Build();
host.Run();
}
} }
} }
...@@ -12,31 +12,22 @@ namespace Pi.Hub.Api ...@@ -12,31 +12,22 @@ namespace Pi.Hub.Api
{ {
public class Startup public class Startup
{ {
public Startup(IHostingEnvironment env) public Startup(IConfiguration configuration)
{ {
var builder = new ConfigurationBuilder() Configuration = configuration;
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
} }
public IConfigurationRoot Configuration { get; } public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container. // This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
// Add framework services.
services.AddMvc(); services.AddMvc();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{ {
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseMvc(); app.UseMvc();
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment