-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStartup.cs
41 lines (39 loc) · 1.48 KB
/
Startup.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
namespace AwesomeServerSample
{
public class Startup
{
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
var logger = loggerFactory.CreateLogger<Program>();
app.MapWhen(c => c.Request.Path == "/test1", config =>
{
config.Run(async (context) =>
{
logger.LogInformation("Invoking Test1 endpoint");
context.Response.StatusCode = 200;
await context.Response.WriteAsync("Hello from Test1!");
});
})
.MapWhen(c => c.Request.Path == "/test2", config =>
{
config.Run(async (context) =>
{
context.Response.StatusCode = 200;
logger.LogInformation("Invoking Test2 endpoint");
await context.Response.WriteAsync("HELLO FROM TEST2!");
});
})
.Run(async (context) =>
{
context.Response.StatusCode = 404;
logger.LogInformation("Invoking NotFound endpoint");
await context.Response.WriteAsync("Not Found");
});
}
}
}