Revize 68d7a219
Přidáno uživatelem Vojtěch Bartička před téměř 3 roky(ů)
Backend/.dockerignore | ||
---|---|---|
1 |
**/.classpath |
|
2 |
**/.dockerignore |
|
3 |
**/.env |
|
4 |
**/.git |
|
5 |
**/.gitignore |
|
6 |
**/.project |
|
7 |
**/.settings |
|
8 |
**/.toolstarget |
|
9 |
**/.vs |
|
10 |
**/.vscode |
|
11 |
**/*.*proj.user |
|
12 |
**/*.dbmdl |
|
13 |
**/*.jfm |
|
14 |
**/azds.yaml |
|
15 |
**/bin |
|
16 |
**/charts |
|
17 |
**/docker-compose* |
|
18 |
**/Dockerfile* |
|
19 |
**/node_modules |
|
20 |
**/npm-debug.log |
|
21 |
**/obj |
|
22 |
**/secrets.dev.yaml |
|
23 |
**/values.dev.yaml |
|
24 |
LICENSE |
|
25 |
README.md |
Backend/Backend.sln | ||
---|---|---|
1 |
|
|
2 |
Microsoft Visual Studio Solution File, Format Version 12.00 |
|
3 |
# Visual Studio Version 17 |
|
4 |
VisualStudioVersion = 17.1.32228.430 |
|
5 |
MinimumVisualStudioVersion = 10.0.40219.1 |
|
6 |
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backend", "Backend\Backend.csproj", "{31E7A829-3F1D-41F6-B189-86449966E060}" |
|
7 |
EndProject |
|
8 |
Global |
|
9 |
GlobalSection(SolutionConfigurationPlatforms) = preSolution |
|
10 |
Debug|Any CPU = Debug|Any CPU |
|
11 |
Release|Any CPU = Release|Any CPU |
|
12 |
EndGlobalSection |
|
13 |
GlobalSection(ProjectConfigurationPlatforms) = postSolution |
|
14 |
{31E7A829-3F1D-41F6-B189-86449966E060}.Debug|Any CPU.ActiveCfg = Debug|Any CPU |
|
15 |
{31E7A829-3F1D-41F6-B189-86449966E060}.Debug|Any CPU.Build.0 = Debug|Any CPU |
|
16 |
{31E7A829-3F1D-41F6-B189-86449966E060}.Release|Any CPU.ActiveCfg = Release|Any CPU |
|
17 |
{31E7A829-3F1D-41F6-B189-86449966E060}.Release|Any CPU.Build.0 = Release|Any CPU |
|
18 |
EndGlobalSection |
|
19 |
GlobalSection(SolutionProperties) = preSolution |
|
20 |
HideSolutionNode = FALSE |
|
21 |
EndGlobalSection |
|
22 |
GlobalSection(ExtensibilityGlobals) = postSolution |
|
23 |
SolutionGuid = {5324355B-DC27-4187-9788-968039764275} |
|
24 |
EndGlobalSection |
|
25 |
EndGlobal |
Backend/Backend/Backend.csproj | ||
---|---|---|
1 |
<Project Sdk="Microsoft.NET.Sdk.Web"> |
|
2 |
|
|
3 |
<PropertyGroup> |
|
4 |
<TargetFramework>net6.0</TargetFramework> |
|
5 |
<Nullable>enable</Nullable> |
|
6 |
<ImplicitUsings>enable</ImplicitUsings> |
|
7 |
<UserSecretsId>092a92d3-0425-42b0-aa80-0cbbb950a8e8</UserSecretsId> |
|
8 |
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS> |
|
9 |
</PropertyGroup> |
|
10 |
|
|
11 |
<ItemGroup> |
|
12 |
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" /> |
|
13 |
<PackageReference Include="Serilog" Version="2.10.0" /> |
|
14 |
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" /> |
|
15 |
<PackageReference Include="Serilog.Sinks.Seq" Version="5.1.1" /> |
|
16 |
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" /> |
|
17 |
</ItemGroup> |
|
18 |
|
|
19 |
</Project> |
Backend/Backend/Controllers/WeatherForecastController.cs | ||
---|---|---|
1 |
using Microsoft.AspNetCore.Mvc; |
|
2 |
|
|
3 |
namespace Backend.Controllers |
|
4 |
{ |
|
5 |
[ApiController] |
|
6 |
[Route("[controller]")] |
|
7 |
public class WeatherForecastController : ControllerBase |
|
8 |
{ |
|
9 |
private static readonly string[] Summaries = new[] |
|
10 |
{ |
|
11 |
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" |
|
12 |
}; |
|
13 |
|
|
14 |
private readonly ILogger<WeatherForecastController> _logger; |
|
15 |
|
|
16 |
public WeatherForecastController(ILogger<WeatherForecastController> logger) |
|
17 |
{ |
|
18 |
_logger = logger; |
|
19 |
} |
|
20 |
|
|
21 |
[HttpGet(Name = "GetWeatherForecast")] |
|
22 |
public IEnumerable<WeatherForecast> Get() |
|
23 |
{ |
|
24 |
return Enumerable.Range(1, 5).Select(index => new WeatherForecast |
|
25 |
{ |
|
26 |
Date = DateTime.Now.AddDays(index), |
|
27 |
TemperatureC = Random.Shared.Next(-20, 55), |
|
28 |
Summary = Summaries[Random.Shared.Next(Summaries.Length)] |
|
29 |
}) |
|
30 |
.ToArray(); |
|
31 |
} |
|
32 |
} |
|
33 |
} |
Backend/Backend/Dockerfile | ||
---|---|---|
1 |
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. |
|
2 |
|
|
3 |
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base |
|
4 |
WORKDIR /app |
|
5 |
EXPOSE 80 |
|
6 |
EXPOSE 443 |
|
7 |
|
|
8 |
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build |
|
9 |
WORKDIR /src |
|
10 |
COPY ["Backend/Backend.csproj", "Backend/"] |
|
11 |
RUN dotnet restore "Backend/Backend.csproj" |
|
12 |
COPY . . |
|
13 |
WORKDIR "/src/Backend" |
|
14 |
RUN dotnet build "Backend.csproj" -c Release -o /app/build |
|
15 |
|
|
16 |
FROM build AS publish |
|
17 |
RUN dotnet publish "Backend.csproj" -c Release -o /app/publish |
|
18 |
|
|
19 |
FROM base AS final |
|
20 |
WORKDIR /app |
|
21 |
COPY --from=publish /app/publish . |
|
22 |
ENTRYPOINT ["dotnet", "Backend.dll"] |
Backend/Backend/Program.cs | ||
---|---|---|
1 |
using Serilog; |
|
2 |
|
|
3 |
var builder = WebApplication.CreateBuilder(args); |
|
4 |
|
|
5 |
// Logging |
|
6 |
builder.Host.UseSerilog((ctx, lc) => lc.WriteTo.Console()); |
|
7 |
|
|
8 |
builder.Services.AddControllers(); |
|
9 |
|
|
10 |
// Swagger |
|
11 |
builder.Services.AddEndpointsApiExplorer(); |
|
12 |
builder.Services.AddSwaggerGen(); |
|
13 |
|
|
14 |
var app = builder.Build(); |
|
15 |
|
|
16 |
// Configure the HTTP request pipeline. |
|
17 |
if (app.Environment.IsDevelopment()) |
|
18 |
{ |
|
19 |
app.UseSwagger(); |
|
20 |
app.UseSwaggerUI(); |
|
21 |
} |
|
22 |
|
|
23 |
app.UseHttpsRedirection(); |
|
24 |
app.UseAuthorization(); |
|
25 |
|
|
26 |
app.MapControllers(); |
|
27 |
|
|
28 |
// Logging |
|
29 |
app.UseSerilogRequestLogging(); |
|
30 |
app.Logger.LogInformation("Starting up"); |
|
31 |
|
|
32 |
app.Run(); |
Backend/Backend/Properties/launchSettings.json | ||
---|---|---|
1 |
{ |
|
2 |
"$schema": "https://json.schemastore.org/launchsettings.json", |
|
3 |
"iisSettings": { |
|
4 |
"windowsAuthentication": false, |
|
5 |
"anonymousAuthentication": true, |
|
6 |
"iisExpress": { |
|
7 |
"applicationUrl": "http://localhost:53037", |
|
8 |
"sslPort": 44379 |
|
9 |
} |
|
10 |
}, |
|
11 |
"profiles": { |
|
12 |
"Backend": { |
|
13 |
"commandName": "Project", |
|
14 |
"launchBrowser": true, |
|
15 |
"launchUrl": "swagger", |
|
16 |
"environmentVariables": { |
|
17 |
"ASPNETCORE_ENVIRONMENT": "Development" |
|
18 |
}, |
|
19 |
"applicationUrl": "https://localhost:7241;http://localhost:5241", |
|
20 |
"dotnetRunMessages": true |
|
21 |
}, |
|
22 |
"IIS Express": { |
|
23 |
"commandName": "IISExpress", |
|
24 |
"launchBrowser": true, |
|
25 |
"launchUrl": "swagger", |
|
26 |
"environmentVariables": { |
|
27 |
"ASPNETCORE_ENVIRONMENT": "Development" |
|
28 |
} |
|
29 |
}, |
|
30 |
"Docker": { |
|
31 |
"commandName": "Docker", |
|
32 |
"launchBrowser": true, |
|
33 |
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger", |
|
34 |
"publishAllPorts": true, |
|
35 |
"useSSL": true |
|
36 |
} |
|
37 |
} |
|
38 |
} |
Backend/Backend/WeatherForecast.cs | ||
---|---|---|
1 |
namespace Backend |
|
2 |
{ |
|
3 |
public class WeatherForecast |
|
4 |
{ |
|
5 |
public DateTime Date { get; set; } |
|
6 |
|
|
7 |
public int TemperatureC { get; set; } |
|
8 |
|
|
9 |
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); |
|
10 |
|
|
11 |
public string? Summary { get; set; } |
|
12 |
} |
|
13 |
} |
Backend/Backend/appsettings.Development.json | ||
---|---|---|
1 |
{ |
|
2 |
"Logging": { |
|
3 |
"LogLevel": { |
|
4 |
"Default": "Information", |
|
5 |
"Microsoft.AspNetCore": "Warning" |
|
6 |
} |
|
7 |
} |
|
8 |
} |
Backend/Backend/appsettings.json | ||
---|---|---|
1 |
{ |
|
2 |
"Logging": { |
|
3 |
"LogLevel": { |
|
4 |
"Default": "Information", |
|
5 |
"Microsoft.AspNetCore": "Warning" |
|
6 |
} |
|
7 |
}, |
|
8 |
"AllowedHosts": "*" |
|
9 |
} |
Také k dispozici: Unified diff
Created backend project, logging setup done