Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
80 lines (56 loc) · 1.97 KB
/
Copy pathProgram.cs
File metadata and controls
80 lines (56 loc) · 1.97 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using GrpcPactPlugin.Services;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using System.Text.Json;
// Additional configuration is required to successfully run gRPC on macOS.
// For instructions on how to configure Kestrel and gRPC clients on macOS, visit https://go.microsoft.com/fwlink/?linkid=2099682
// app.Run();
public class InitMessage
{
public int Port { get; set; }
public string? ServerKey { get; set; }
}
class PactPluginServer
{
public static async Task Main()
{
try
{
await RunAsync();
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine("Global error thrown. Exiting");
throw;
}
}
private static async Task RunAsync()
{
var builder = WebApplication.CreateBuilder();
builder.WebHost.ConfigureKestrel(options =>
{
// Setup a HTTP/2 endpoint without TLS.
options.ListenLocalhost(5117, o => o.Protocols =
HttpProtocols.Http2);
});
// Add services to the container.
builder.Services.AddGrpc();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.MapGrpcService<PactPluginService>();
var initMessage = new InitMessage();
initMessage.Port = 5117;
initMessage.ServerKey = "76bee28c-97b9-47c1-9684-30cb1e273051";
var serializeOptions = new JsonSerializerOptions
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
};
string jsonString = JsonSerializer.Serialize<InitMessage>(initMessage, serializeOptions);
app.Start();
Console.WriteLine("Application started.");
Console.WriteLine("Press any key to stop the server...");
await Task.Delay(2000);
Console.WriteLine(jsonString);
await app.WaitForShutdownAsync();
}
}