初始化
This commit is contained in:
49
BLWLogServer/Program.cs
Normal file
49
BLWLogServer/Program.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using BLWLogServer.Services;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace BLWLogServer
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(name: "KuaYu",
|
||||
policy =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyHeader()
|
||||
.AllowAnyMethod();
|
||||
});
|
||||
});
|
||||
builder.Services.AddScoped<IMongoClient>(ppp =>
|
||||
{
|
||||
string? connectionString = builder.Configuration["Mongodb:Connectstr"];
|
||||
//var connectionString = "mongodb://localhost:27017/";
|
||||
var client = new MongoClient(connectionString);
|
||||
return client;
|
||||
});
|
||||
builder.Services.AddHostedService<KafkaConsume>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
|
||||
app.UseCors("KuaYu");
|
||||
app.UseAuthorization();
|
||||
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user