feat: Enhance static file serving and routing for development and production environments #3
This commit is contained in:
@@ -7,7 +7,6 @@ stages: # Define the stages of the pipeline.
|
|||||||
web-build: # This job runs in the build stage, which runs first.
|
web-build: # This job runs in the build stage, which runs first.
|
||||||
stage: build
|
stage: build
|
||||||
image: node:24
|
image: node:24
|
||||||
parallel: 2
|
|
||||||
script:
|
script:
|
||||||
- cd Web
|
- cd Web
|
||||||
- npm install
|
- npm install
|
||||||
@@ -22,7 +21,6 @@ web-build: # This job runs in the build stage, which runs first.
|
|||||||
api-build:
|
api-build:
|
||||||
stage: build
|
stage: build
|
||||||
image: mcr.microsoft.com/dotnet/sdk:8.0
|
image: mcr.microsoft.com/dotnet/sdk:8.0
|
||||||
parallel: 2
|
|
||||||
script:
|
script:
|
||||||
- cd Api
|
- cd Api
|
||||||
- dotnet publish Api.csproj --output ./build --runtime linux-x64 --configuration Release --self-contained true
|
- dotnet publish Api.csproj --output ./build --runtime linux-x64 --configuration Release --self-contained true
|
||||||
|
|||||||
3
Api/.gitignore
vendored
3
Api/.gitignore
vendored
@@ -1,4 +1,5 @@
|
|||||||
obj/
|
obj/
|
||||||
bin/
|
bin/
|
||||||
.vs/
|
.vs/
|
||||||
build/
|
build/
|
||||||
|
**/core
|
||||||
@@ -56,6 +56,51 @@ namespace Api
|
|||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
var staticFilePath = "/workspaces/centrum/Web/dist/Web/browser";
|
||||||
|
app.UseDefaultFiles(new DefaultFilesOptions
|
||||||
|
{
|
||||||
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(staticFilePath),
|
||||||
|
DefaultFileNames = new List<string> { "index.html" }
|
||||||
|
});
|
||||||
|
app.UseStaticFiles(new StaticFileOptions
|
||||||
|
{
|
||||||
|
FileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(staticFilePath),
|
||||||
|
RequestPath = ""
|
||||||
|
});
|
||||||
|
// Angular routing fallback
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
await next();
|
||||||
|
var path = context.Request.Path.Value ?? string.Empty;
|
||||||
|
if (context.Response.StatusCode == 404 &&
|
||||||
|
!System.IO.Path.HasExtension(path) &&
|
||||||
|
!path.StartsWith("/api"))
|
||||||
|
{
|
||||||
|
context.Request.Path = "/index.html";
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.UseDefaultFiles(); // Uses wwwroot by default
|
||||||
|
app.UseStaticFiles();
|
||||||
|
// Angular routing fallback for production
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
await next();
|
||||||
|
var path = context.Request.Path.Value ?? string.Empty;
|
||||||
|
if (context.Response.StatusCode == 404 &&
|
||||||
|
!System.IO.Path.HasExtension(path) &&
|
||||||
|
!path.StartsWith("/api"))
|
||||||
|
{
|
||||||
|
context.Request.Path = "/index.html";
|
||||||
|
await next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
app.UseAuthentication();
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user