Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9bce77a08e | ||
|
|
8c7f4ac12f | ||
|
|
856c70d4ac | ||
|
|
dfa9fbf909 | ||
|
|
883315bc30 | ||
|
|
4ed517ac90 | ||
|
|
eacbbc3071 | ||
|
|
ee3a3a9d56 | ||
|
|
61672c5770 | ||
|
|
c6b9746603 |
@@ -3,20 +3,7 @@ name: PublishNugetPackage
|
|||||||
on: [create]
|
on: [create]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
|
||||||
name: Build Project
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v1
|
|
||||||
- name: Setup .NET Core
|
|
||||||
uses: actions/setup-dotnet@v1
|
|
||||||
with:
|
|
||||||
dotnet-version: '3.1.101'
|
|
||||||
- name: Build
|
|
||||||
run: dotnet build
|
|
||||||
|
|
||||||
publish:
|
publish:
|
||||||
needs: build
|
|
||||||
name: Publish Project to Nuget
|
name: Publish Project to Nuget
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
@@ -24,11 +11,11 @@ jobs:
|
|||||||
- name: Setup .NET Core
|
- name: Setup .NET Core
|
||||||
uses: actions/setup-dotnet@v1
|
uses: actions/setup-dotnet@v1
|
||||||
with:
|
with:
|
||||||
dotnet-version: '3.1.101'
|
dotnet-version: '5.0.100'
|
||||||
- name: Publish
|
- name: Publish
|
||||||
run: |
|
run: |
|
||||||
version=`git describe --tags`
|
version=`git describe --tags`
|
||||||
dotnet pack --configuration release -p:PackageVersion=$version
|
dotnet build --configuration release -p:PackageVersion=$version
|
||||||
dotnet nuget push bin/release/Simcu.SimApi.$version.nupkg -k ${NUGET_APIKEY} -s https://www.nuget.org/api/v2/package
|
dotnet nuget push bin/release/Simcu.SimApi.$version.nupkg -k ${NUGET_APIKEY} -s https://www.nuget.org/api/v2/package
|
||||||
env:
|
env:
|
||||||
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
|
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY }}
|
||||||
|
|||||||
@@ -110,10 +110,13 @@ namespace SimApi.Communications
|
|||||||
/// 动态内容列表
|
/// 动态内容列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public T List { get; set; }
|
public T List { get; set; }
|
||||||
|
|
||||||
//当前页码
|
//当前页码
|
||||||
public int Page { get; set; }
|
public int Page { get; set; }
|
||||||
|
|
||||||
//每页条数
|
//每页条数
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
//总计条数
|
//总计条数
|
||||||
public int Total { get; set; }
|
public int Total { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ namespace SimApi.Controllers
|
|||||||
/// <param name="code">错误代码</param>
|
/// <param name="code">错误代码</param>
|
||||||
/// <param name="message">错误描述(若是常规错误,代码可自动带取描述)</param>
|
/// <param name="message">错误描述(若是常规错误,代码可自动带取描述)</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
protected static void Error(int code = 500, string message = "服务器错误")
|
protected static void Error(int code = 500, string message = "")
|
||||||
{
|
{
|
||||||
throw new SimApiException(code, message);
|
throw new SimApiException(code, message);
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ namespace SimApi.Controllers
|
|||||||
/// <param name="condition">检测条件</param>
|
/// <param name="condition">检测条件</param>
|
||||||
/// <param name="code">错误代码</param>
|
/// <param name="code">错误代码</param>
|
||||||
/// <param name="message">错误描述</param>
|
/// <param name="message">错误描述</param>
|
||||||
protected static void ErrorWhen(bool condition, int code = 500, string message = "服务器错误")
|
protected static void ErrorWhen(bool condition, int code = 500, string message = "")
|
||||||
{
|
{
|
||||||
if (condition)
|
if (condition)
|
||||||
{
|
{
|
||||||
@@ -72,7 +72,7 @@ namespace SimApi.Controllers
|
|||||||
/// <param name="condition">检测条件</param>
|
/// <param name="condition">检测条件</param>
|
||||||
/// <param name="code">错误代码</param>
|
/// <param name="code">错误代码</param>
|
||||||
/// <param name="message">错误描述</param>
|
/// <param name="message">错误描述</param>
|
||||||
protected static void ErrorWhenNull(object condition, int code = 404, string message = "资源不存在")
|
protected static void ErrorWhenNull(object condition, int code = 404, string message = "")
|
||||||
{
|
{
|
||||||
ErrorWhen(condition == null, code, message);
|
ErrorWhen(condition == null, code, message);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using SimApi.Communications;
|
using SimApi.Communications;
|
||||||
@@ -32,6 +33,13 @@ namespace SimApi.Middlewares
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await Next(context);
|
await Next(context);
|
||||||
|
if (context.Response.StatusCode != 200)
|
||||||
|
{
|
||||||
|
if (!new[] {301, 302}.Contains(context.Response.StatusCode))
|
||||||
|
{
|
||||||
|
throw new SimApiException(context.Response.StatusCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (SimApiException ex)
|
catch (SimApiException ex)
|
||||||
{
|
{
|
||||||
@@ -43,6 +51,7 @@ namespace SimApi.Middlewares
|
|||||||
{
|
{
|
||||||
response.SetCodeMsg(ex.Code, ex.Message);
|
response.SetCodeMsg(ex.Code, ex.Message);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorResponse(context, response);
|
ErrorResponse(context, response);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
# YYApi 基于Asp.net Core 3的一个基础辅助包
|
# YYApi 基于Asp.net Core 3/5的一个基础辅助包
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,6 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net5.0</TargetFramework>
|
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<PackOnBuild>true</PackOnBuild>
|
<PackOnBuild>true</PackOnBuild>
|
||||||
<Version>0.2.3</Version>
|
<Version>0.2.3</Version>
|
||||||
@@ -13,6 +12,9 @@
|
|||||||
<IncludeSymbols>true</IncludeSymbols>
|
<IncludeSymbols>true</IncludeSymbols>
|
||||||
<ReleaseVersion>5.0.0</ReleaseVersion>
|
<ReleaseVersion>5.0.0</ReleaseVersion>
|
||||||
<SynchReleaseVersion>false</SynchReleaseVersion>
|
<SynchReleaseVersion>false</SynchReleaseVersion>
|
||||||
|
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
|
||||||
|
<PackageVersion>5.0.2</PackageVersion>
|
||||||
|
<TargetFrameworks>net5.0;netcoreapp3.1</TargetFrameworks>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'YYApi' " />
|
<PropertyGroup Condition=" '$(RunConfiguration)' == 'YYApi' " />
|
||||||
|
|||||||
+12
-2
@@ -5,6 +5,7 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||||
using SimApi.Middlewares;
|
using SimApi.Middlewares;
|
||||||
|
using Microsoft.AspNetCore.HttpOverrides;
|
||||||
|
|
||||||
namespace SimApi
|
namespace SimApi
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,16 @@ namespace SimApi
|
|||||||
public static IServiceCollection AddSimApi(this IServiceCollection builder, string title,
|
public static IServiceCollection AddSimApi(this IServiceCollection builder, string title,
|
||||||
string description = null)
|
string description = null)
|
||||||
{
|
{
|
||||||
return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload();
|
return builder.AddSimApiAuth().AddSimApiDoc(title, description).AddCors().AddSimApiUpload().Configure<ForwardedHeadersOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor |
|
||||||
|
ForwardedHeaders.XForwardedProto;
|
||||||
|
// Only loopback proxies are allowed by default.
|
||||||
|
// Clear that restriction because forwarders are enabled by explicit
|
||||||
|
// configuration.
|
||||||
|
options.KnownNetworks.Clear();
|
||||||
|
options.KnownProxies.Clear();
|
||||||
|
}); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -41,7 +51,7 @@ namespace SimApi
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder, params SubmitMethod[] submitMethods)
|
public static IApplicationBuilder UseSimApi(this IApplicationBuilder builder, params SubmitMethod[] submitMethods)
|
||||||
{
|
{
|
||||||
return builder.UseSimApiException().UseSimApiDoc(submitMethods).UseMiddleware<SimApiAuthMiddleware>().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload();
|
return builder.UseSimApiException().UseSimApiDoc(submitMethods).UseMiddleware<SimApiAuthMiddleware>().UseCors(x => x.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()).UseSimApiUpload().UseForwardedHeaders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user