You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB
C#

using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using ZKLT.Hadoop;
namespace ZKLT.Hadoop.API
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
#region Cors跨域
builder.Services.AddCors(options =>
{
options.AddPolicy("all", builder =>
{
builder.SetIsOriginAllowed(origin => true) //允许任何来源的主机访问
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials();//指定处理cookie
});
});
#endregion
// Add services to the container.
builder.Services.AddControllers().AddNewtonsoftJson(options =>
{
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
});
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddHadoop();
var app = builder.Build();
#region Cors跨域
app.UseCors("all");
#endregion
//app.UseHadoop((c) =>
//{
// c.Host = "127.0.0.1";
// c.Account = "root";
// c.PassWord = "root";
// c.Key = "hadoopdb";
// c.Port = 3306;
//});
app.UseHadoop((c) =>
{
c.Host = app.Configuration["ConnectionStrings:Host"];
c.Account = app.Configuration["ConnectionStrings:Account"];
c.PassWord = app.Configuration["ConnectionStrings:PassWord"];
c.Key = app.Configuration["ConnectionStrings:Key"];
c.Port = Convert.ToInt32(app.Configuration["ConnectionStrings:Port"]);
});
//app.UseHadoop((c) =>
//{
// c.Host = "118.195.165.218";
// c.Account = "root";
// c.PassWord = "root";
// c.Key = "testdb";
// c.Port = 4000;
//});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}