-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (46 loc) · 1.72 KB
/
Program.cs
File metadata and controls
57 lines (46 loc) · 1.72 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
using TextAnalysisAPI.Services;
using Microsoft.OpenApi.Models;
using System.Reflection;
namespace TextAnalysisAPI;
/// <summary>
/// The main entry point for the application.
/// </summary>
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Configure the server to listen on specific ports
builder.WebHost.ConfigureKestrel(serverOptions =>
{
serverOptions.ListenLocalhost(5198); // Set HTTP port
serverOptions.ListenLocalhost(7193, listenOptions =>
{
listenOptions.UseHttps(); // Set HTTPS port
});
});
builder.Services.AddScoped<ITextAnalysisService, TextAnalysisService>(); // Register TextAnalysisService
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
// Register the Swagger generator for API documentation
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Text Analysis API", Version = "v1" });
// Include the XML comments in the API documentation in Swagger
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
// Enable Swagger for API documentation
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.MapControllers();
app.Run();
}
}