-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (80 loc) · 2.62 KB
/
Program.cs
File metadata and controls
98 lines (80 loc) · 2.62 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using Microsoft.AspNetCore.Localization;
using System.Globalization;
using Newtonsoft.Json;
using FBRExtension.Extensions;
using FBRExtension.Helpers;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.DateFormatHandling = DateFormatHandling.IsoDateFormat;
});
// Add CORS
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAll", policy =>
{
policy.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
// Add simple HttpClient for API calls
builder.Services.AddHttpClient("PralFbrClient", client =>
{
client.Timeout = TimeSpan.FromSeconds(120);
})
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler()
{
AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate
});
// Add default HttpClient for other uses
builder.Services.AddHttpClient();
// Save log
string? homeDir = Environment.GetEnvironmentVariable("HOME");
string logDirectory = homeDir != null
? Path.Combine(homeDir, "LogFiles", "MyApp") // Azure
: Path.Combine(AppContext.BaseDirectory, "Logs"); // Local
if (!Directory.Exists(logDirectory))
{
Directory.CreateDirectory(logDirectory);
}
// Konfigurasi logging
builder.Logging.ClearProviders();
builder.Logging.AddConsole();
builder.Logging.AddProvider(new FileLoggerProvider(logDirectory, LogLevel.Information));
// Simplified configuration without complex service dependencies
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
// Use global exception handling in production
app.UseGlobalExceptionHandling();
}
// Use request localization
var defaultCulture = new CultureInfo("en-US");
var localizationOptions = new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(defaultCulture),
SupportedCultures = new List<CultureInfo> { defaultCulture },
SupportedUICultures = new List<CultureInfo> { defaultCulture }
};
app.UseRequestLocalization(localizationOptions);
app.UseRouting();
app.UseCors("AllowAll");
// Force HTTPS redirection for all routes
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapControllers();
// Serve index.html as default for non-API routes
app.MapFallbackToFile("index.html").Add(endpointBuilder =>
{
endpointBuilder.Metadata.Add(new HttpMethodMetadata(new[] { "GET" }));
});
app.Run();