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
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());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue