Na most működig SWAGGER és 5000 porton publishban is !
This commit is contained in:
@@ -4,16 +4,19 @@
|
||||
{
|
||||
private readonly RequestDelegate _next;
|
||||
private const string ApiKeyHeaderName = "X-Api-Key";
|
||||
private readonly ILogger<ApiKeyMiddleware> _logger;
|
||||
|
||||
public ApiKeyMiddleware(RequestDelegate next)
|
||||
public ApiKeyMiddleware(RequestDelegate next, ILogger<ApiKeyMiddleware> logger)
|
||||
{
|
||||
_next = next;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InvokeAsync(HttpContext context)
|
||||
{
|
||||
if (!context.Request.Headers.TryGetValue(ApiKeyHeaderName, out var extractedApiKey))
|
||||
{
|
||||
_logger.LogWarning("API Key is missing.");
|
||||
context.Response.StatusCode = 401; // Unauthorized
|
||||
context.Response.ContentType = "text/html; charset=utf-8";
|
||||
await context.Response.WriteAsync("API Key hiányzik.");
|
||||
@@ -25,6 +28,7 @@
|
||||
|
||||
if (!apiKey.Equals(extractedApiKey))
|
||||
{
|
||||
_logger.LogWarning("Invalid API Key.");
|
||||
context.Response.StatusCode = 403; // Forbidden
|
||||
context.Response.ContentType = "text/html; charset=utf-8";
|
||||
await context.Response.WriteAsync("Helytelen API Key.");
|
||||
|
||||
@@ -10,20 +10,41 @@ namespace WorkFlowCheck.API.Controllers
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
private IUserService _userService;
|
||||
|
||||
public UserController(IUserService userService)
|
||||
{
|
||||
_userService = userService;
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<ApiResponseDTO<UserDTO>> Get()
|
||||
|
||||
[HttpGet("{id}")]
|
||||
public async Task<ApiResponseDTO<UserDTO>> Get(int id)
|
||||
{
|
||||
var userDTO = await _userService.GetUser(1);
|
||||
var retVal = new ApiResponseDTO<UserDTO>()
|
||||
{
|
||||
IsSuccess = true,
|
||||
Data = userDTO
|
||||
};
|
||||
|
||||
var userDTO = await _userService.GetUser(id);
|
||||
|
||||
if (userDTO != null)
|
||||
{
|
||||
if (userDTO.Id == 0)
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No match!");
|
||||
retVal.Data = userDTO;
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = true;
|
||||
retVal.Data = userDTO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
retVal.IsSuccess = false;
|
||||
retVal.Errors.Add("No data!");
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,18 +11,13 @@ using WorkFlowCheck.BL.Infra;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console() // Logok írása a konzolra
|
||||
.WriteTo.File("logs/WorkFlowCheck.log", rollingInterval: RollingInterval.Day) // Logok fájlba
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.CreateLogger();
|
||||
|
||||
//builder.WebHost.ConfigureKestrel(options =>
|
||||
//{
|
||||
// options.ListenAnyIP(5069, listenOptions =>
|
||||
// {
|
||||
// listenOptions.UseHttps(Path.Combine(AppContext.BaseDirectory, "Certs", "SwaggerCert.pfx"), "Noispot135!Xy()zz654321");
|
||||
// });
|
||||
//});
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||
|
||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||
@@ -78,7 +73,10 @@ builder.Services.AddControllers()
|
||||
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
|
||||
});
|
||||
|
||||
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Swagger middleware
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
@@ -91,11 +89,10 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
// Routing és endpointok
|
||||
app.UseHttpsRedirection();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseMiddleware<ApiKeyMiddleware>();
|
||||
app.MapControllers();
|
||||
app.UseAuthorization();
|
||||
|
||||
app.Run();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "todos",
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
},
|
||||
@@ -13,7 +13,7 @@
|
||||
"IIS Express": {
|
||||
"commandName": "IISExpress",
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "todos",
|
||||
"launchUrl": "swagger",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>false</InvariantGlobalization>
|
||||
<PublishAot>false</PublishAot>
|
||||
<IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WorkFlowCheck.BL\WorkFlowCheck.BL.csproj" />
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Verbose"
|
||||
"Microsoft.AspNetCore": "Information"
|
||||
}
|
||||
},
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Verbose",
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "Console"
|
||||
@@ -18,7 +18,7 @@
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/log-.txt",
|
||||
"path": "logs/log-.log",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,12 @@ namespace WorkFlowCheck.BL.DTO
|
||||
{
|
||||
public class ApiResponseBaseDTO
|
||||
{
|
||||
public ApiResponseBaseDTO()
|
||||
{
|
||||
Errors = new List<string>();
|
||||
}
|
||||
public bool IsSuccess { get; set; }
|
||||
public IEnumerable<string> Errors { get; set; }
|
||||
public List<string> Errors { get; set; }
|
||||
public bool HandleError { get; set; }
|
||||
public string Error
|
||||
{
|
||||
@@ -16,17 +20,17 @@ namespace WorkFlowCheck.BL.DTO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class ApiResponseDTO : ApiResponseBaseDTO
|
||||
{
|
||||
public object Data { get; set; }
|
||||
}
|
||||
|
||||
|
||||
public interface IApiResponseDTO<out T>
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class ApiResponseDTO<T> : ApiResponseBaseDTO, IApiResponseDTO<T>
|
||||
{
|
||||
public T Data { get; set; }
|
||||
|
||||
Reference in New Issue
Block a user