This commit is contained in:
Natlinux81
2025-04-21 16:55:15 +02:00
commit d5f6034a28
39 changed files with 15372 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<SpaRoot>..\ClientApp\</SpaRoot>
<SpaProxyServerUrl>http://localhost:44492</SpaProxyServerUrl>
<SpaProxyLaunchCommand>npm start</SpaProxyLaunchCommand>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="9.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="8.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="8.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="8.1.1" />
</ItemGroup>
</Project>
+6
View File
@@ -0,0 +1,6 @@
@API_HostAddress = http://localhost:5114
GET {{API_HostAddress}}/weatherforecast/
Accept: application/json
###
+10
View File
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc;
namespace API.Controllers;
[ApiController]
[Route("api/[controller]")]
public class BaseApiController : ControllerBase
{
}
@@ -0,0 +1,19 @@
using Microsoft.OpenApi.Models;
namespace API.Extension;
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddWebServices(this IServiceCollection services)
{
services.AddSwaggerGen(options =>
{
// update the name and version of the document
options.SwaggerDoc("v1", new OpenApiInfo { Title = "DotNetAngular API", Version = "v1" });
// update names of the api
options.SwaggerGeneratorOptions.DocumentFilters.Add(new LowerCaseDocumentFilter());
});
return services;
}
}
+53
View File
@@ -0,0 +1,53 @@
using API.Extension;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddControllers();
builder.Services.AddWebServices();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowLocalhost",
policy =>
{
policy.WithOrigins("http://localhost:44492")
.AllowAnyHeader()
.AllowAnyMethod();
});
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment() || app.Environment.IsEnvironment("Test"))
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseCors("AllowLocalhost");
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.UseStaticFiles();
app.Run();
public class LowerCaseDocumentFilter : IDocumentFilter
{
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
// get the paths
var paths = swaggerDoc.Paths.ToDictionary(
path => path.Key.ToLowerInvariant(),
path => swaggerDoc.Paths[path.Key]);
// add the paths
swaggerDoc.Paths = new OpenApiPaths();
foreach (var pathItem in paths) swaggerDoc.Paths.Add(pathItem.Key, pathItem.Value);
}
}
+42
View File
@@ -0,0 +1,42 @@
{
"profiles": {
"swagger_dev": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7091;http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"swagger_test": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7091;http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "test"
}
},
"Angular_test": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:7091;http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Test",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
},
"Angular_dev": {
"commandName": "Project",
"launchBrowser": false,
"applicationUrl": "https://localhost:7091;http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
}
}
+8
View File
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
+9
View File
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}