Serves public website, admin SPA, and API from a single host
Shared hosting (e.g. mijnhostingpartner.nl) typically allows only one site/app-pool, so SlpModularCms.Api now serves everything itself: '/' for the customer's public website (deployed separately, not part of this repo), '/admin' for the CMS admin SPA, and '/api/v1' for the API as before. - Program.cs: static files from wwwroot + SPA fallbacks per path so client-side routing works for both frontends. - frontend/: builds with base '/admin/' in production (dev unchanged), router basepath follows suit. - SlpModularCms.Api.csproj: publish now builds the admin frontend and copies its output into wwwroot/admin automatically. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wi5qHAuq8UbzN4NLUFeKkJ
This commit is contained in:
@@ -46,6 +46,12 @@ if (app.Environment.IsDevelopment())
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
// Serve the public website ('/') and the CMS admin SPA ('/admin') from wwwroot.
|
||||
// wwwroot/index.html + assets -> public website (built and deployed separately, not part of this repo)
|
||||
// wwwroot/admin/index.html + assets -> CMS admin build (see frontend/, copied in on publish)
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
|
||||
app.UseCors();
|
||||
|
||||
// 7. Use Module Middleware
|
||||
@@ -56,4 +62,9 @@ app.UseAuthorization();
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
// SPA fallbacks so client-side routes (e.g. /admin/dashboard) resolve to the right index.html
|
||||
// instead of 404ing. The "nonfile" constraint keeps genuinely missing assets (e.g. /admin/assets/x.js) as 404s.
|
||||
app.MapFallbackToFile("/admin/{*path:nonfile}", "admin/index.html");
|
||||
app.MapFallbackToFile("{*path:nonfile}", "index.html");
|
||||
|
||||
app.Run();
|
||||
|
||||
@@ -24,4 +24,23 @@
|
||||
<ProjectReference Include="..\SlpModularCms.Modules.Master\SlpModularCms.Modules.Master.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
Builds the CMS admin SPA (frontend/) and copies its output into wwwroot/admin so it's served
|
||||
at the /admin path (see Program.cs). Only runs on `dotnet publish`, not on every dev build.
|
||||
The public website ('/') lives outside this repo and is deployed into wwwroot separately.
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<AdminFrontendDir>$(MSBuildProjectDirectory)/../../frontend</AdminFrontendDir>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="BuildAndCopyAdminFrontend" BeforeTargets="Publish">
|
||||
<Message Importance="high" Text="Building CMS admin frontend ($(AdminFrontendDir))..." />
|
||||
<Exec Command="pnpm install --frozen-lockfile" WorkingDirectory="$(AdminFrontendDir)" />
|
||||
<Exec Command="pnpm build" WorkingDirectory="$(AdminFrontendDir)" />
|
||||
<ItemGroup>
|
||||
<AdminFrontendFiles Include="$(AdminFrontendDir)/dist/**/*" />
|
||||
</ItemGroup>
|
||||
<Copy SourceFiles="@(AdminFrontendFiles)" DestinationFolder="$(MSBuildProjectDirectory)/wwwroot/admin/%(RecursiveDir)" SkipUnchangedFiles="true" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user