-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
38 lines (28 loc) · 1.59 KB
/
Program.cs
File metadata and controls
38 lines (28 loc) · 1.59 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
using OcrGrpcWrapper.Services;
var builder = WebApplication.CreateBuilder(args);
// 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
// Retrieve necessary environment variables
string temporaryStoragePath = Environment.GetEnvironmentVariable("TEMPORARY_STORAGE")
?? throw new InvalidOperationException("TEMPORARY_STORAGE environment variable is not set.");
string cliExecutablePath = Environment.GetEnvironmentVariable("CLI_EXECUTABLE_PATH")
?? throw new InvalidOperationException("CLI_EXECUTABLE_PATH environment variable is not set.");
string? licenseFilePath = Environment.GetEnvironmentVariable("LICENSE_PATH");
if (!Directory.Exists(temporaryStoragePath))
{
Directory.CreateDirectory(temporaryStoragePath);
}
// gRPC server MUST have server reflection enabled.
// Server reflection is necessary for grpcurl to discover the services and methods available on the server.
builder.Services.AddSingleton(new OcrService(temporaryStoragePath, licenseFilePath, cliExecutablePath));
// Add gRPC services to the container.
builder.Services.AddGrpc();
builder.Services.AddGrpcReflection();
var app = builder.Build();
app.MapGet("/",
() =>
"Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.MapGrpcService<OcrService>();
// Enable reflection
app.MapGrpcReflectionService();
app.Run();