1 Star 0 Fork 12

唵湜咜尒娦/CardGame

forked from 倾河丶/CardGame 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
Startup.cs 2.77 KB
一键复制 编辑 原始数据 按行查看 历史
13934305056 提交于 2021-11-24 10:45 . 'first'
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using CardGame.Server;
using Swashbuckle.AspNetCore.Filters;
using System;
using System.IO;
using System.Reflection;
namespace CardGame
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers(x =>
{
//swagger自定义忽略过滤器
x.Conventions.Add(new Filters.SwaggerApiExplorer());
});
services.AddCors(o =>
{
//o.AddDefaultPolicy(b =>
//{
// b.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod();
//});
o.AddPolicy("cors", policy =>
{
policy.AllowAnyHeader().AllowAnyMethod().AllowCredentials().WithOrigins("http://192.168.3.121:8080");
});
});
services.AddSignalR();
//注册swagger服务
services.AddSwaggerGen(x =>
{
x.SwaggerDoc("client", new OpenApiInfo { Title = "client", Version = "v1.0" });
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
x.IncludeXmlComments(xmlPath, true);
x.OperationFilter<AddResponseHeadersFilter>();
x.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
x.OperationFilter<SecurityRequirementsOperationFilter>();
x.AddSecurityDefinition("JWT", new OpenApiSecurityScheme
{
Description = "如接口需授权,请输入token(无需bearer)\"",
Name = "Authorization",
In = ParameterLocation.Header,
Type = SecuritySchemeType.ApiKey,
Scheme = "bearer"
});
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCors("cors");
app.UseRouting();
app.UseWebSockets();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapHub<SignalRHub>("/mj");
});
if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(x =>
{
x.SwaggerEndpoint("/swagger/client/swagger.json", "client");
x.DocExpansion(Swashbuckle.AspNetCore.SwaggerUI.DocExpansion.None);
});
}
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/xiaoyaoxingchen666/card-game.git
git@gitee.com:xiaoyaoxingchen666/card-game.git
xiaoyaoxingchen666
card-game
CardGame
master

搜索帮助