63 lines
1.9 KiB
C#
63 lines
1.9 KiB
C#
using ScrapperAPI.Bus;
|
|
using ScrapperAPI.Factories;
|
|
using ScrapperAPI.Hub;
|
|
using ScrapperAPI.Interfaces;
|
|
using ScrapperAPI.Options;
|
|
using ScrapperAPI.Repositories;
|
|
using ScrapperAPI.Services;
|
|
using ScrapperAPI.Utils;
|
|
using ScrapperAPI.Workers;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.AddOpenApi();
|
|
builder.Services.AddSignalR();
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.Configure<ScraperOptions>(builder.Configuration.GetSection("Scraper"));
|
|
|
|
builder.Services.AddSingleton<IDomainRateLimiter>(sp =>
|
|
{
|
|
var opts = sp.GetRequiredService<Microsoft.Extensions.Options.IOptions<ScraperOptions>>().Value;
|
|
return new DomainRateLimiter(opts.RateLimit.PerDomainMinDelayMs);
|
|
});
|
|
builder.Services.AddSingleton<IScrapeEventBus, SignalRScrapeEventBus>();
|
|
builder.Services.AddSingleton<IScraperHttpClient, ScraperHttpClient>();
|
|
builder.Services.AddSingleton<IDbConnectionFactory, NpgsqlConnectionFactory>();
|
|
|
|
builder.Services.AddScoped<ISessionRepository, SessionRepository>();
|
|
builder.Services.AddScoped<IQueueRepository, QueueRepository>();
|
|
builder.Services.AddScoped<IContentRepository, ContentRepository>();
|
|
|
|
builder.Services.AddHttpClient("scraper", c => c.Timeout = TimeSpan.FromSeconds(30));
|
|
|
|
builder.Services.AddSingleton<IScrapeCoordinator, ScrapeCoordinator>();
|
|
builder.Services.AddHostedService(sp => (ScrapeCoordinator)sp.GetRequiredService<IScrapeCoordinator>());
|
|
|
|
builder.Services.AddCors(options =>
|
|
{
|
|
options.AddPolicy("AllowReact",
|
|
policy =>
|
|
{
|
|
policy.WithOrigins("http://localhost:3000")
|
|
.AllowAnyHeader()
|
|
.AllowAnyMethod()
|
|
.AllowCredentials();
|
|
});
|
|
});
|
|
|
|
var app = builder.Build();
|
|
|
|
app.UseCors("AllowReact");
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.MapOpenApi();
|
|
}
|
|
|
|
app.MapControllers();
|
|
app.MapHub<ScrapeHub>("/ws/scrape");
|
|
|
|
// app.UseHttpsRedirection();
|
|
|
|
app.Run(); |