mirror of
https://github.com/real-zony/ZonyLrcToolsX.git
synced 2025-07-01 04:00:42 +00:00
feat: Integrated SPA resources with ASP.NET Core.
This commit is contained in:
parent
f57afd4238
commit
bccfaaaa5b
2
.gitignore
vendored
2
.gitignore
vendored
@ -450,3 +450,5 @@ fabric.properties
|
||||
.idea/
|
||||
/.idea
|
||||
/src/ZonyLrcTools.Cli/TempFiles/
|
||||
|
||||
src/ZonyLrcTools.LocalServer/UiStaticResources/*
|
@ -6,9 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C29FB05C-54B1-4020-94D2-87E192EB2F98}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{AF8ADB2F-E46C-4DEE-8316-652D9FE1A69B}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
tests\.gitignore = tests\.gitignore
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ZonyLrcTools.Cli", "src\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj", "{55D74323-ABFA-4A73-A3BF-F3E8D5DE6DE8}"
|
||||
EndProject
|
||||
|
@ -1,3 +1,4 @@
|
||||
using System.Diagnostics;
|
||||
using ZonyLrcTools.LocalServer;
|
||||
|
||||
var app = RegisterAndConfigureServices();
|
||||
@ -12,25 +13,42 @@ async Task ListenServices()
|
||||
WebApplication? RegisterAndConfigureServices()
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
builder.WebHost.ConfigureKestrel(k => k.ListenAnyIP(50002));
|
||||
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
var insideApp = builder.Build();
|
||||
insideApp.UseSpaStaticFiles(new StaticFileOptions
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
RequestPath = "",
|
||||
FileProvider = new Microsoft.Extensions.FileProviders
|
||||
.ManifestEmbeddedFileProvider(
|
||||
typeof(Program).Assembly, "UiStaticResources"
|
||||
)
|
||||
});
|
||||
|
||||
insideApp.UseAuthorization();
|
||||
insideApp.MapControllers();
|
||||
insideApp.Lifetime.ApplicationStarted.Register(OpenBrowser);
|
||||
|
||||
return insideApp;
|
||||
}
|
||||
|
||||
void OpenBrowser()
|
||||
{
|
||||
const string url = "http://localhost:50002/index.html";
|
||||
|
||||
if (OperatingSystem.IsWindows())
|
||||
{
|
||||
Process.Start("explorer.exe", url);
|
||||
}
|
||||
else if (OperatingSystem.IsMacOS())
|
||||
{
|
||||
Process.Start("open", url);
|
||||
}
|
||||
else if (OperatingSystem.IsLinux())
|
||||
{
|
||||
Process.Start("xdg-open", url);
|
||||
}
|
||||
|
||||
app.UseAuthorization();
|
||||
app.MapControllers();
|
||||
|
||||
return app;
|
||||
}
|
@ -5,7 +5,6 @@
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": true,
|
||||
"launchUrl": "swagger",
|
||||
"applicationUrl": "http://localhost:50002",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
|
@ -4,23 +4,26 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.9" />
|
||||
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="6.0.9" />
|
||||
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
|
||||
<PackageReference Include="SuperSocket.WebSocket" Version="2.0.0-beta.11" />
|
||||
<PackageReference Include="SuperSocket.WebSocket.Server" Version="2.0.0-beta.11" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Controllers" />
|
||||
<Folder Include="Controllers" />
|
||||
<EmbeddedResource Include="UiStaticResources\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />
|
||||
</ItemGroup>
|
||||
<!-- <ItemGroup>-->
|
||||
<!-- <ProjectReference Include="..\ZonyLrcTools.Cli\ZonyLrcTools.Cli.csproj" />-->
|
||||
<!-- </ItemGroup>-->
|
||||
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user