mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-06 18:52:27 +00:00
Split API into its own project
This commit is contained in:
parent
2aa803f69f
commit
47271d1798
16 changed files with 336 additions and 162 deletions
35
ProjectLighthouse.API/Program.cs
Normal file
35
ProjectLighthouse.API/Program.cs
Normal file
|
@ -0,0 +1,35 @@
|
|||
using LBPUnion.ProjectLighthouse.Logging.Loggers.AspNet;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Settings;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.API;
|
||||
|
||||
public static class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
StartupTasks.Run(args, ServerType.Api);
|
||||
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
=> Host.CreateDefaultBuilder(args)
|
||||
.ConfigureWebHostDefaults
|
||||
(
|
||||
webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<ApiStartup>();
|
||||
webBuilder.UseUrls(ServerConfiguration.Instance.ListenUrl);
|
||||
}
|
||||
)
|
||||
.ConfigureLogging
|
||||
(
|
||||
logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.Services.TryAddEnumerable(ServiceDescriptor.Singleton<ILoggerProvider, AspNetToLighthouseLoggerProvider>());
|
||||
}
|
||||
);
|
||||
}
|
45
ProjectLighthouse.API/ProjectLighthouse.API.csproj
Normal file
45
ProjectLighthouse.API/ProjectLighthouse.API.csproj
Normal file
|
@ -0,0 +1,45 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<AssemblyName>LBPUnion.ProjectLighthouse.API</AssemblyName>
|
||||
<RootNamespace>LBPUnion.ProjectLighthouse.API</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ProjectLighthouse\ProjectLighthouse.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="gitVersion.txt"/>
|
||||
<EmbeddedResource Include="gitVersion.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="gitBranch.txt"/>
|
||||
<EmbeddedResource Include="gitBranch.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="gitRemotes.txt"/>
|
||||
<EmbeddedResource Include="gitRemotes.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
<None Remove="gitUnpushed.txt"/>
|
||||
<EmbeddedResource Include="gitUnpushed.txt">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
<Exec Command="git describe --long --always --dirty --exclude=\* --abbrev=8 > "$(ProjectDir)/gitVersion.txt""/>
|
||||
<Exec Command="git branch --show-current > "$(ProjectDir)/gitBranch.txt""/>
|
||||
<Exec Command="git remote -v > "$(ProjectDir)/gitRemotes.txt""/>
|
||||
<Exec Command="git log --branches --not --remotes --oneline > "$(ProjectDir)/gitUnpushed.txt""/>
|
||||
</Target>
|
||||
</Project>
|
75
ProjectLighthouse.API/Startup/ApiStartup.cs
Normal file
75
ProjectLighthouse.API/Startup/ApiStartup.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using LBPUnion.ProjectLighthouse.Helpers;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Startup.Middlewares;
|
||||
using Microsoft.OpenApi.Models;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.API;
|
||||
|
||||
public class ApiStartup
|
||||
{
|
||||
public ApiStartup(IConfiguration configuration)
|
||||
{
|
||||
this.Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
|
||||
services.AddMvc
|
||||
(
|
||||
options =>
|
||||
{
|
||||
options.OutputFormatters.Add(new JsonOutputFormatter());
|
||||
}
|
||||
);
|
||||
|
||||
services.AddDbContext<Database>();
|
||||
|
||||
services.AddSwaggerGen
|
||||
(
|
||||
c =>
|
||||
{
|
||||
// Give swagger the name and version of our project
|
||||
c.SwaggerDoc
|
||||
(
|
||||
"v1",
|
||||
new OpenApiInfo
|
||||
{
|
||||
Title = "Project Lighthouse API",
|
||||
Version = "v1",
|
||||
}
|
||||
);
|
||||
|
||||
// Filter out endpoints not in /api/v1
|
||||
c.DocumentFilter<SwaggerFilter>();
|
||||
|
||||
// Add XMLDoc to swagger
|
||||
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, "LBPUnion.ProjectLighthouse.API.xml"));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public virtual void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
#if DEBUG
|
||||
app.UseDeveloperExceptionPage();
|
||||
#endif
|
||||
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI
|
||||
(
|
||||
c =>
|
||||
{
|
||||
c.SwaggerEndpoint("v1/swagger.json", "Project Lighthouse API");
|
||||
}
|
||||
);
|
||||
|
||||
app.UseMiddleware<RequestLogMiddleware>();
|
||||
|
||||
app.UseRouting();
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
}
|
||||
}
|
8
ProjectLighthouse.API/appsettings.Development.json
Normal file
8
ProjectLighthouse.API/appsettings.Development.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
9
ProjectLighthouse.API/appsettings.json
Normal file
9
ProjectLighthouse.API/appsettings.json
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue