Compare commits

...

18 Commits

Author SHA1 Message Date
1c27bffa73 build: remove pdb files
All checks were successful
Build and Deploy Docker Container / build-and-deploy (push) Successful in 1m48s
.NET Test Pipeline / build-and-test (push) Successful in 2m6s
2024-07-05 02:28:18 +03:00
76fd1347ce build: add ACTUAL_SUB_PATH 2024-07-05 01:59:54 +03:00
820828276e fix: get sub url without first "api" 2024-07-05 01:59:36 +03:00
ac4804e864 fix: get host name without port 2024-07-05 01:58:14 +03:00
21055176ac fix: check file exist 2024-07-05 01:57:34 +03:00
f42caa3a45 feat: add sub path for actual url 2024-07-05 01:35:19 +03:00
57f4d1b822 fix: add test env to variablesFromFile 2024-07-05 01:22:21 +03:00
cdb738ca42 fix: set default port 8080 2024-07-05 01:11:24 +03:00
d45c865f4e feat: add listen port from env 2024-07-05 00:44:55 +03:00
d87654a355 ref: update 2024-07-04 23:57:44 +03:00
75c1aebea6 refactor: change namespace 2024-07-04 23:54:17 +03:00
17e20fee2e refactor: Admin 2024-07-04 23:52:25 +03:00
e8ca2c42a6 sec: add random scret forward token for set ip if app under proxy 2024-07-04 23:46:43 +03:00
9133b57a1b refactor: GeneralConfig 2024-07-04 23:45:33 +03:00
05ca45db49 perf: precompile regex 2024-07-04 23:39:12 +03:00
7e2016080f style: compact css 2024-07-04 23:37:16 +03:00
fe24dfcd6a perf: return Dictionary instead interface 2024-07-04 23:31:05 +03:00
2041a187e7 fix: create directory if not exist 2024-07-04 22:40:59 +03:00
25 changed files with 225 additions and 935 deletions

18
.env
View File

@ -9,7 +9,7 @@
# General # General
# The path to save the data. # The path to save the data
# string # string
# (optional) # (optional)
# Saving logs (if the full path is not specified), # Saving logs (if the full path is not specified),
@ -18,6 +18,22 @@
# If you want to change this value, you need to change the values in Settings.json and move the file itself to the desired location. # If you want to change this value, you need to change the values in Settings.json and move the file itself to the desired location.
PATH_TO_SAVE= PATH_TO_SAVE=
# The actual sub path to the api
# string
# (optional)
ACTUAL_SUB_PATH=
# The sub path to the swagger
# string
# (optional)
SWAGGER_SUB_PATH=swagger
# Internal port configuration
# integer
# (optional)
# Specify the internal port on which the server will listen.
INTERNAL_PORT=8080
# Security # Security
# JWT signature token # JWT signature token

View File

@ -75,6 +75,7 @@ jobs:
-e SECURITY_HASH_SIZE=$SECURITY_HASH_SIZE \ -e SECURITY_HASH_SIZE=$SECURITY_HASH_SIZE \
-e SECURITY_HASH_TOKEN=$SECURITY_HASH_TOKEN \ -e SECURITY_HASH_TOKEN=$SECURITY_HASH_TOKEN \
-e SECURITY_SALT_SIZE=$SECURITY_SALT_SIZE \ -e SECURITY_SALT_SIZE=$SECURITY_SALT_SIZE \
-e ACTUAL_SUB_PATH=api \
$DOCKER_IMAGE $DOCKER_IMAGE
" "

View File

@ -15,9 +15,10 @@ ENV NUGET_PASSWORD=$NUGET_PASSWORD
RUN dotnet restore ./Backend.sln --configfile nuget.config RUN dotnet restore ./Backend.sln --configfile nuget.config
WORKDIR /app WORKDIR /app
WORKDIR /src WORKDIR /src
RUN dotnet publish ./Endpoint/Endpoint.csproj -c Release -o /app RUN dotnet publish ./Endpoint/Endpoint.csproj -c Release --self-contained false -p:PublishSingleFile=false -o /app
FROM base AS final FROM base AS final
WORKDIR /app WORKDIR /app
COPY --from=build /app . COPY --from=build /app .
RUN find . -name "*.pdb" -type f -delete
ENTRYPOINT ["dotnet", "Mirea.Api.Endpoint.dll"] ENTRYPOINT ["dotnet", "Mirea.Api.Endpoint.dll"]

View File

@ -1,10 +0,0 @@
namespace Mirea.Api.Endpoint.Common.Model;
public class Admin
{
public const string PathToSave = "admin.json";
public required string Username { get; set; }
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public required string Salt { get; set; }
}

View File

@ -0,0 +1,46 @@
using Microsoft.AspNetCore.Http;
using System;
using System.Linq;
namespace Mirea.Api.Endpoint.Common.Services;
public static class UrlHelper
{
public static string CurrentDomain(HttpContext context) =>
context.Request.Headers["X-Forwarded-Host"].FirstOrDefault() ?? context.Request.Host.Host;
private static string CreateSubPath(string? path)
{
if (string.IsNullOrEmpty(path))
return "/";
return "/" + path.Trim('/') + "/";
}
public static string GetSubPath => CreateSubPath(Environment.GetEnvironmentVariable("ACTUAL_SUB_PATH"));
public static string GetSubPathWithoutFirstApiName
{
get
{
var path = GetSubPath;
if (string.IsNullOrEmpty(path) || path == "/")
return CreateSubPath(null);
var parts = path.Split('/', StringSplitOptions.RemoveEmptyEntries);
for (int i = 0; i < parts.Length; i++)
{
if (!parts[i].Equals("api", StringComparison.CurrentCultureIgnoreCase)) continue;
parts = parts.Take(i).Concat(parts.Skip(i + 1)).ToArray();
break;
}
return CreateSubPath(string.Join("/", parts));
}
}
public static string GetSubPathSwagger => CreateSubPath(Environment.GetEnvironmentVariable("SWAGGER_SUB_PATH"));
}

View File

@ -0,0 +1,25 @@
using Mirea.Api.Endpoint.Common.Services;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Mirea.Api.Endpoint.Common.Settings;
public class Admin : ISaveSettings
{
[JsonIgnore] private const string FileName = "admin.json";
[JsonIgnore]
public static string FilePath => PathBuilder.Combine(FileName);
public required string Username { get; set; }
public required string Email { get; set; }
public required string PasswordHash { get; set; }
public required string Salt { get; set; }
public void SaveSetting()
{
File.WriteAllText(FilePath, JsonSerializer.Serialize(this));
}
}

View File

@ -0,0 +1,33 @@
using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.General.Settings;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace Mirea.Api.Endpoint.Common.Settings;
public class GeneralConfig : ISaveSettings
{
[JsonIgnore] private const string FileName = "Settings.json";
[JsonIgnore]
public static string FilePath => PathBuilder.Combine(FileName);
public DbSettings? DbSettings { get; set; }
public CacheSettings? CacheSettings { get; set; }
public ScheduleSettings? ScheduleSettings { get; set; }
public EmailSettings? EmailSettings { get; set; }
public LogSettings? LogSettings { get; set; }
public string? SecretForwardToken { get; set; }
public void SaveSetting()
{
File.WriteAllText(
FilePath,
JsonSerializer.Serialize(this, new JsonSerializerOptions
{
WriteIndented = true
})
);
}
}

View File

@ -0,0 +1,5 @@
namespace Mirea.Api.Endpoint.Common.Settings;
public interface ISaveSettings
{
void SaveSetting();
}

View File

@ -1,6 +1,6 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings;
namespace Mirea.Api.Endpoint.Configuration.AppConfig; namespace Mirea.Api.Endpoint.Configuration.AppConfig;

View File

@ -9,9 +9,9 @@ namespace Mirea.Api.Endpoint.Configuration.AppConfig;
public static class EnvironmentConfiguration public static class EnvironmentConfiguration
{ {
private static IDictionary<string, string> LoadEnvironment(string envFile) private static Dictionary<string, string> LoadEnvironment(string envFile)
{ {
Dictionary<string, string> environment = new(); Dictionary<string, string> environment = [];
if (!File.Exists(envFile)) return environment; if (!File.Exists(envFile)) return environment;
@ -46,6 +46,10 @@ public static class EnvironmentConfiguration
{ {
var variablesFromFile = LoadEnvironment(".env"); var variablesFromFile = LoadEnvironment(".env");
#if DEBUG
LoadEnvironment(".env.develop").ToList().ForEach(x => variablesFromFile.Add(x.Key, x.Value));
#endif
var environmentVariables = Environment.GetEnvironmentVariables() var environmentVariables = Environment.GetEnvironmentVariables()
.OfType<DictionaryEntry>() .OfType<DictionaryEntry>()
.ToDictionary( .ToDictionary(
@ -57,12 +61,18 @@ public static class EnvironmentConfiguration
.AddInMemoryCollection(environmentVariables!) .AddInMemoryCollection(environmentVariables!)
.AddInMemoryCollection(variablesFromFile!); .AddInMemoryCollection(variablesFromFile!);
#if DEBUG if (variablesFromFile.TryGetValue("PATH_TO_SAVE", out var pathToSave))
result.AddInMemoryCollection(LoadEnvironment(".env.develop")!); {
#endif Environment.SetEnvironmentVariable("PATH_TO_SAVE", pathToSave);
if (!Directory.Exists(pathToSave))
Directory.CreateDirectory(pathToSave);
}
if (variablesFromFile.TryGetValue("PATH_TO_SAVE", out var data)) if (variablesFromFile.TryGetValue("ACTUAL_SUB_PATH", out var actualSubPath))
Environment.SetEnvironmentVariable("PATH_TO_SAVE", variablesFromFile["PATH_TO_SAVE"]); Environment.SetEnvironmentVariable("ACTUAL_SUB_PATH", actualSubPath);
if (variablesFromFile.TryGetValue("SWAGGER_SUB_PATH", out var swaggerSubPath))
Environment.SetEnvironmentVariable("SWAGGER_SUB_PATH", swaggerSubPath);
return result.Build(); return result.Build();
} }

View File

@ -2,7 +2,7 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Common.Settings;
using Serilog; using Serilog;
using Serilog.Events; using Serilog.Events;
using Serilog.Filters; using Serilog.Filters;

View File

@ -1,7 +1,7 @@
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Mirea.Api.Endpoint.Common.Services.Security; using Mirea.Api.Endpoint.Common.Services.Security;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings;
using Mirea.Api.Security; using Mirea.Api.Security;
using Mirea.Api.Security.Common.Interfaces; using Mirea.Api.Security.Common.Interfaces;

View File

@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Microsoft.OpenApi.Models; using Microsoft.OpenApi.Models;
using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.Swagger; using Mirea.Api.Endpoint.Configuration.Swagger;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
using System; using System;
@ -43,7 +44,10 @@ public static class SwaggerConfiguration
} }
}); });
if (File.Exists(Path.Combine(basePath, "docs.xml")))
options.IncludeXmlComments(Path.Combine(basePath, "docs.xml")); options.IncludeXmlComments(Path.Combine(basePath, "docs.xml"));
if (File.Exists(Path.Combine(basePath, "ApiDtoDocs.xml")))
options.IncludeXmlComments(Path.Combine(basePath, "ApiDtoDocs.xml")); options.IncludeXmlComments(Path.Combine(basePath, "ApiDtoDocs.xml"));
}); });
@ -65,6 +69,7 @@ public static class SwaggerConfiguration
var url = $"/swagger/{description.GroupName}/swagger.json"; var url = $"/swagger/{description.GroupName}/swagger.json";
var name = description.GroupName.ToUpperInvariant(); var name = description.GroupName.ToUpperInvariant();
options.SwaggerEndpoint(url, name); options.SwaggerEndpoint(url, name);
options.RoutePrefix = UrlHelper.GetSubPathSwagger.Trim('/');
} }
}); });

View File

@ -1,14 +0,0 @@
using Mirea.Api.Endpoint.Configuration.General.Settings;
namespace Mirea.Api.Endpoint.Configuration.General;
public class GeneralConfig
{
public const string FilePath = "Settings.json";
public DbSettings? DbSettings { get; set; }
public CacheSettings? CacheSettings { get; set; }
public ScheduleSettings? ScheduleSettings { get; set; }
public EmailSettings? EmailSettings { get; set; }
public LogSettings? LogSettings { get; set; }
}

View File

@ -1,4 +1,5 @@
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Endpoint.Configuration.General.Attributes; using Mirea.Api.Endpoint.Configuration.General.Attributes;
using Mirea.Api.Endpoint.Configuration.General.Interfaces; using Mirea.Api.Endpoint.Configuration.General.Interfaces;
using System; using System;

View File

@ -8,9 +8,8 @@ using Mirea.Api.Dto.Requests.Configuration;
using Mirea.Api.Endpoint.Common.Attributes; using Mirea.Api.Endpoint.Common.Attributes;
using Mirea.Api.Endpoint.Common.Exceptions; using Mirea.Api.Endpoint.Common.Exceptions;
using Mirea.Api.Endpoint.Common.Interfaces; using Mirea.Api.Endpoint.Common.Interfaces;
using Mirea.Api.Endpoint.Common.Model;
using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Endpoint.Configuration.General.Settings; using Mirea.Api.Endpoint.Configuration.General.Settings;
using Mirea.Api.Endpoint.Configuration.General.Validators; using Mirea.Api.Endpoint.Configuration.General.Validators;
using Mirea.Api.Security.Services; using Mirea.Api.Security.Services;
@ -24,7 +23,6 @@ using System.IO;
using System.Net.Mail; using System.Net.Mail;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
namespace Mirea.Api.Endpoint.Controllers.Configuration; namespace Mirea.Api.Endpoint.Controllers.Configuration;
@ -33,7 +31,7 @@ namespace Mirea.Api.Endpoint.Controllers.Configuration;
[ApiController] [ApiController]
[MaintenanceModeIgnore] [MaintenanceModeIgnore]
[ApiExplorerSettings(IgnoreApi = true)] [ApiExplorerSettings(IgnoreApi = true)]
public class SetupController( public partial class SetupController(
ISetupToken setupToken, ISetupToken setupToken,
IMaintenanceModeNotConfigureService notConfigureService, IMaintenanceModeNotConfigureService notConfigureService,
IMemoryCache cache, IMemoryCache cache,
@ -55,7 +53,7 @@ public class SetupController(
if (!notConfigureService.IsMaintenanceMode) if (!notConfigureService.IsMaintenanceMode)
throw new ControllerArgumentException( throw new ControllerArgumentException(
"The token cannot be generated because the server has been configured. " + "The token cannot be generated because the server has been configured. " +
$"If you need to restart the configuration, then delete the \"{PathBuilder.Combine(GeneralConfig.FilePath)}\" file and restart the application."); $"If you need to restart the configuration, then delete the \"{GeneralConfig.FilePath}\" file and restart the application.");
var token = new byte[32]; var token = new byte[32];
RandomNumberGenerator.Create().GetBytes(token); RandomNumberGenerator.Create().GetBytes(token);
@ -71,11 +69,11 @@ public class SetupController(
Response.Cookies.Append("AuthToken", token, new CookieOptions Response.Cookies.Append("AuthToken", token, new CookieOptions
{ {
HttpOnly = false, Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
Secure = false, Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext),
Path = "/" Secure = true,
HttpOnly = true
}); });
return Ok(true); return Ok(true);
} }
@ -208,7 +206,7 @@ public class SetupController(
[BadRequestResponse] [BadRequestResponse]
public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user) public ActionResult<string> CreateAdmin([FromBody] CreateUserRequest user)
{ {
if (user.Password.Length < 8 || !Regex.IsMatch(user.Password, "[A-Z]+") || !Regex.IsMatch(user.Password, "[!@#$%^&*]+")) if (user.Password.Length < 8 || !PasswordExistUpperLetter().IsMatch(user.Password) || !PasswordExistSpecialSymbol().IsMatch(user.Password))
throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character."); throw new ControllerArgumentException("The password must be at least 8 characters long and contain at least one uppercase letter and one special character.");
if (!MailAddress.TryCreate(user.Email, out _)) if (!MailAddress.TryCreate(user.Email, out _))
@ -333,19 +331,15 @@ public class SetupController(
if (!cache.TryGetValue(CacheAdminKey, out Admin? admin) || admin == null) if (!cache.TryGetValue(CacheAdminKey, out Admin? admin) || admin == null)
throw new ControllerArgumentException("The administrator's data was not set."); throw new ControllerArgumentException("The administrator's data was not set.");
if (System.IO.File.Exists(PathBuilder.Combine(GeneralConfig.FilePath))) admin.SaveSetting();
System.IO.File.Delete(PathBuilder.Combine(GeneralConfig.FilePath)); GeneralConfig.SaveSetting();
System.IO.File.WriteAllText(PathBuilder.Combine(Admin.PathToSave), JsonSerializer.Serialize(admin));
System.IO.File.WriteAllText(
PathBuilder.Combine(GeneralConfig.FilePath),
JsonSerializer.Serialize(GeneralConfig, new JsonSerializerOptions
{
WriteIndented = true
})
);
return true; return true;
} }
[GeneratedRegex("[A-Z]+")]
private static partial Regex PasswordExistUpperLetter();
[GeneratedRegex("[!@#$%^&*]+")]
private static partial Regex PasswordExistSpecialSymbol();
} }

View File

@ -6,7 +6,8 @@ using Microsoft.Extensions.Options;
using Mirea.Api.Dto.Common; using Mirea.Api.Dto.Common;
using Mirea.Api.Dto.Requests; using Mirea.Api.Dto.Requests;
using Mirea.Api.Dto.Responses; using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Model; using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Security.Common.Dto.Requests; using Mirea.Api.Security.Common.Dto.Requests;
using Mirea.Api.Security.Services; using Mirea.Api.Security.Services;
using System; using System;
@ -28,8 +29,8 @@ public class AuthController(IOptionsSnapshot<Admin> user, AuthService auth, Pass
var cookieOptions = new CookieOptions var cookieOptions = new CookieOptions
{ {
Expires = expires, Expires = expires,
Path = "/api", Path = UrlHelper.GetSubPathWithoutFirstApiName + "api",
Domain = Request.Headers["X-Forwarded-Host"], Domain = UrlHelper.CurrentDomain(ControllerContext.HttpContext),
Secure = true, Secure = true,
HttpOnly = true HttpOnly = true
}; };

View File

@ -8,7 +8,7 @@ using Mirea.Api.Dto.Requests;
using Mirea.Api.Dto.Responses; using Mirea.Api.Dto.Responses;
using Mirea.Api.Endpoint.Common.Attributes; using Mirea.Api.Endpoint.Common.Attributes;
using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Common.Settings;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

View File

@ -5,9 +5,9 @@
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Winsomnia</Company> <Company>Winsomnia</Company>
<Version>1.0.0-a0</Version> <Version>1.0.0-b0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.1.0</FileVersion>
<AssemblyName>Mirea.Api.Endpoint</AssemblyName> <AssemblyName>Mirea.Api.Endpoint</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
@ -31,12 +31,12 @@
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" /> <PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" /> <PackageReference Include="Serilog.Formatting.Compact" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" /> <PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" /> <PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.6" /> <PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.6" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.6.2" /> <PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.6.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Versioning" Version="2.0.0" /> <PackageReference Include="Swashbuckle.AspNetCore.Versioning" Version="2.0.0" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.0" /> <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="7.6.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
@ -6,12 +8,13 @@ using Mirea.Api.DataAccess.Application;
using Mirea.Api.DataAccess.Persistence; using Mirea.Api.DataAccess.Persistence;
using Mirea.Api.DataAccess.Persistence.Common; using Mirea.Api.DataAccess.Persistence.Common;
using Mirea.Api.Endpoint.Common.Interfaces; using Mirea.Api.Endpoint.Common.Interfaces;
using Mirea.Api.Endpoint.Common.Model;
using Mirea.Api.Endpoint.Common.Services; using Mirea.Api.Endpoint.Common.Services;
using Mirea.Api.Endpoint.Common.Settings;
using Mirea.Api.Endpoint.Configuration.AppConfig; using Mirea.Api.Endpoint.Configuration.AppConfig;
using Mirea.Api.Endpoint.Configuration.General; using Mirea.Api.Endpoint.Configuration.General;
using Mirea.Api.Endpoint.Configuration.General.Validators; using Mirea.Api.Endpoint.Configuration.General.Validators;
using Mirea.Api.Endpoint.Middleware; using Mirea.Api.Endpoint.Middleware;
using Mirea.Api.Security.Services;
using System; using System;
using System.IO; using System.IO;
@ -36,9 +39,9 @@ public class Program
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Configuration.AddConfiguration(EnvironmentConfiguration.GetEnvironment()); builder.Configuration.AddConfiguration(EnvironmentConfiguration.GetEnvironment());
builder.Configuration.AddJsonFile(PathBuilder.Combine(GeneralConfig.FilePath), optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile(GeneralConfig.FilePath, optional: true, reloadOnChange: true);
builder.Services.Configure<GeneralConfig>(builder.Configuration); builder.Services.Configure<GeneralConfig>(builder.Configuration);
builder.Configuration.AddJsonFile(PathBuilder.Combine(Admin.PathToSave), optional: true, reloadOnChange: true); builder.Configuration.AddJsonFile(Admin.FilePath, optional: true, reloadOnChange: true);
builder.Services.Configure<Admin>(builder.Configuration); builder.Services.Configure<Admin>(builder.Configuration);
builder.Host.AddCustomSerilog(); builder.Host.AddCustomSerilog();
@ -64,6 +67,26 @@ public class Program
}); });
}); });
builder.WebHost.ConfigureKestrel(options =>
{
options.ListenLocalhost(
int.Parse(builder.Configuration.GetValue<string>("INTERNAL_PORT") ?? "8080"));
});
builder.Services.Configure<ForwardedHeadersOptions>(options =>
{
var secretForward = builder.Configuration.Get<GeneralConfig>();
if (string.IsNullOrEmpty(secretForward!.SecretForwardToken))
{
secretForward.SecretForwardToken = GeneratorKey.GenerateBase64(18);
secretForward.SaveSetting();
}
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.ForwardedForHeaderName = secretForward.SecretForwardToken + "-X-Forwarded-For";
});
builder.Services.AddCustomApiVersioning(); builder.Services.AddCustomApiVersioning();
builder.Services.AddCustomSwagger(); builder.Services.AddCustomSwagger();
@ -72,9 +95,10 @@ public class Program
var app = builder.Build(); var app = builder.Build();
app.UseStaticFiles(); app.UseStaticFiles(UrlHelper.GetSubPath.TrimEnd('/'));
app.UseCors("AllowAll"); app.UseCors("AllowAll");
app.UseCustomSerilog(); app.UseCustomSerilog();
app.UseForwardedHeaders();
using (var scope = app.Services.CreateScope()) using (var scope = app.Services.CreateScope())
{ {

File diff suppressed because one or more lines are too long

View File

@ -5,15 +5,15 @@
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Winsomnia</Company> <Company>Winsomnia</Company>
<Version>1.0.0-a0</Version> <Version>1.0.0-rc0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.2.0</FileVersion>
<AssemblyName>Mirea.Api.Security</AssemblyName> <AssemblyName>Mirea.Api.Security</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.0" /> <PackageReference Include="Konscious.Security.Cryptography.Argon2" Version="1.3.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1" />
</ItemGroup> </ItemGroup>

View File

@ -5,9 +5,9 @@
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Winsomnia</Company> <Company>Winsomnia</Company>
<Version>1.0.0-a0</Version> <Version>1.0.0-rc0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.2.0</FileVersion>
<AssemblyName>Mirea.Api.DataAccess.Application</AssemblyName> <AssemblyName>Mirea.Api.DataAccess.Application</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
</PropertyGroup> </PropertyGroup>

View File

@ -5,9 +5,9 @@
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Winsomnia</Company> <Company>Winsomnia</Company>
<Version>1.0.0-a0</Version> <Version>1.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.3.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.3.0</FileVersion>
<AssemblyName>Mirea.Api.DataAccess.Domain</AssemblyName> <AssemblyName>Mirea.Api.DataAccess.Domain</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
</PropertyGroup> </PropertyGroup>

View File

@ -5,9 +5,9 @@
<ImplicitUsings>disable</ImplicitUsings> <ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<Company>Winsomnia</Company> <Company>Winsomnia</Company>
<Version>1.0.0-a0</Version> <Version>1.0.0-rc0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion> <AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion> <FileVersion>1.0.2.0</FileVersion>
<AssemblyName>Mirea.Api.DataAccess.Persistence</AssemblyName> <AssemblyName>Mirea.Api.DataAccess.Persistence</AssemblyName>
<RootNamespace>$(AssemblyName)</RootNamespace> <RootNamespace>$(AssemblyName)</RootNamespace>
</PropertyGroup> </PropertyGroup>