170 lines
6.2 KiB
C#
170 lines
6.2 KiB
C#
|
|
using LongHuParkApi.Common;
|
|||
|
|
using Microsoft.AspNetCore.Builder;
|
|||
|
|
using Microsoft.AspNetCore.Hosting;
|
|||
|
|
using Microsoft.AspNetCore.Http;
|
|||
|
|
using Microsoft.AspNetCore.Http.Features;
|
|||
|
|
using Microsoft.AspNetCore.Mvc;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
|
using Microsoft.Extensions.FileProviders;
|
|||
|
|
using Microsoft.Extensions.Hosting;
|
|||
|
|
using Microsoft.Extensions.Logging;
|
|||
|
|
using Microsoft.OpenApi.Models;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using PictureFilesApi.Services;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Reflection;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace PictureFilesApi
|
|||
|
|
{
|
|||
|
|
public class Startup
|
|||
|
|
{
|
|||
|
|
public Startup(IConfiguration configuration)
|
|||
|
|
{
|
|||
|
|
Configuration = configuration;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public IConfiguration Configuration { get; }
|
|||
|
|
|
|||
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|||
|
|
public void ConfigureServices(IServiceCollection services)
|
|||
|
|
{
|
|||
|
|
//TODO:<3A><><EFBFBD><EFBFBD>swagger
|
|||
|
|
services.AddSwaggerGen(c =>
|
|||
|
|
{
|
|||
|
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "ͼƬ<CDBC>ļ<EFBFBD>API", Version = "v1" });
|
|||
|
|
// <20><>ȡxml<6D>ļ<EFBFBD><C4BC><EFBFBD>
|
|||
|
|
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
|
|||
|
|
// <20><>ȡxml<6D>ļ<EFBFBD>·<EFBFBD><C2B7>
|
|||
|
|
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
|
|||
|
|
// <20><><EFBFBD>ӿ<EFBFBD><D3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD>ͣ<EFBFBD>true<75><65>ʾ<EFBFBD><CABE>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><D7A2>
|
|||
|
|
c.IncludeXmlComments(xmlPath, true);
|
|||
|
|
|
|||
|
|
c.OperationFilter<SiteIdHeaderParameter>();
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
|
|||
|
|
//TODO:<3A><><EFBFBD><EFBFBD>httpContext
|
|||
|
|
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
|
|||
|
|
services.AddSingleton<PlatformServices>();
|
|||
|
|
|
|||
|
|
services.AddControllers(option =>
|
|||
|
|
{
|
|||
|
|
}).AddNewtonsoftJson(options =>
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>ѭ<EFBFBD><D1AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
|
|||
|
|
//<2F><>ʹ<EFBFBD><CAB9><EFBFBD>շ<EFBFBD><D5B7><EFBFBD>ʽ<EFBFBD><CABD>key
|
|||
|
|
//options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver();
|
|||
|
|
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
//TODO:cache<68><65><EFBFBD><EFBFBD>
|
|||
|
|
services.AddMemoryCache();
|
|||
|
|
//TODO<44><4F><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
services.AddCors(options =>
|
|||
|
|
{
|
|||
|
|
options.AddPolicy("CorsPolicy",
|
|||
|
|
builder => builder.AllowAnyOrigin()
|
|||
|
|
.AllowAnyMethod()
|
|||
|
|
.AllowAnyHeader());
|
|||
|
|
});
|
|||
|
|
//TODO<44><4F><EFBFBD><EFBFBD><EFBFBD>ӹ<EFBFBD><D3B9><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
services.AddMvc(option =>
|
|||
|
|
{
|
|||
|
|
option.Filters.Add(typeof(CustomActionFilter));
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
services.Configure<FormOptions>(x =>
|
|||
|
|
{
|
|||
|
|
x.ValueLengthLimit = int.MaxValue;
|
|||
|
|
x.MultipartBodyLengthLimit = 1073741824;
|
|||
|
|
x.MemoryBufferThreshold = int.MaxValue;
|
|||
|
|
|
|||
|
|
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|||
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|||
|
|
{
|
|||
|
|
if (env.IsDevelopment())
|
|||
|
|
{
|
|||
|
|
app.UseDeveloperExceptionPage();
|
|||
|
|
}
|
|||
|
|
// ʹ<>ÿ<EFBFBD><C3BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
app.UseCors("CorsPolicy");
|
|||
|
|
//<2F><><EFBFBD>Է<EFBFBD><D4B7>ʸ<EFBFBD>Ŀ¼<C4BF><C2BC><EFBFBD><EFBFBD><EFBFBD>ľ<EFBFBD>̬<EFBFBD>ļ<EFBFBD>
|
|||
|
|
//<2F><>̬<EFBFBD>ļ<EFBFBD>ѡ<EFBFBD><D1A1>
|
|||
|
|
var staticfile = new StaticFileOptions
|
|||
|
|
{
|
|||
|
|
FileProvider = new PhysicalFileProvider(AppContext.BaseDirectory),
|
|||
|
|
ContentTypeProvider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider(new Dictionary<string, string>
|
|||
|
|
{
|
|||
|
|
{ ".amr","audio/AMR" },
|
|||
|
|
{ ".apk","application/vnd.android.package-archive" },
|
|||
|
|
{ ".cpg","application/vnd.android.package-archive" },
|
|||
|
|
{ ".dbf","application/vnd.android.package-archive" },
|
|||
|
|
{ ".shp","application/vnd.android.package-archive" },
|
|||
|
|
{ ".shx","application/vnd.android.package-archive" },
|
|||
|
|
{ ".zip","application/zip" },
|
|||
|
|
{ ".jpeg","image/jpeg" },
|
|||
|
|
{ ".jpg","image/jpg" },
|
|||
|
|
{ ".png","image/png" },
|
|||
|
|
{ ".mp4","video/mpeg4" },
|
|||
|
|
{ ".doc","application/octet-stream" },
|
|||
|
|
{ ".docx","application/octet-stream" },
|
|||
|
|
{ ".xls","application/octet-stream" },
|
|||
|
|
{ ".xlsx","application/octet-stream" },
|
|||
|
|
{ ".pdf","application/octet-stream" },
|
|||
|
|
{ ".pptx","application/vnd.openxmlformats-officedocument.presentationml.presentation" },
|
|||
|
|
{ ".dwg","application/acad"},
|
|||
|
|
{ ".rar","application/x-rar-compressed"},
|
|||
|
|
})
|
|||
|
|
};
|
|||
|
|
app.UseStaticFiles(staticfile);
|
|||
|
|
|
|||
|
|
//TODO:<3A><><EFBFBD><EFBFBD>swagger
|
|||
|
|
// <20><><EFBFBD><EFBFBD>Swagger<65>й<EFBFBD><D0B9>м<EFBFBD><D0BC><EFBFBD>
|
|||
|
|
app.UseSwagger();
|
|||
|
|
|
|||
|
|
var useSwagger = Configuration.GetSection("UseSwagger").Value;
|
|||
|
|
if (useSwagger == "1")
|
|||
|
|
{
|
|||
|
|
app.UseSwaggerUI(c =>
|
|||
|
|
{
|
|||
|
|
c.SwaggerEndpoint("/swagger/v1/swagger.json", "<22>汾 v1");
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
app.UseRouting();
|
|||
|
|
|
|||
|
|
|
|||
|
|
app.UseAuthorization();
|
|||
|
|
|
|||
|
|
//<2F><><EFBFBD><EFBFBD>Router·<72><C2B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
app.UseEndpoints(endpoints =>
|
|||
|
|
{
|
|||
|
|
endpoints.Map("/", context =>
|
|||
|
|
{
|
|||
|
|
context.Response.Redirect("swagger");
|
|||
|
|
return Task.CompletedTask;
|
|||
|
|
});
|
|||
|
|
endpoints.Map("weatherforecast", context =>
|
|||
|
|
{
|
|||
|
|
context.Response.Redirect("swagger");
|
|||
|
|
return Task.CompletedTask;
|
|||
|
|
});
|
|||
|
|
endpoints.MapControllerRoute(
|
|||
|
|
name: "default",
|
|||
|
|
pattern: "api/{controller=Values}/{action=Index1}/{id?}"
|
|||
|
|
);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|