Skip to content

Commit

Permalink
BASE_URL support in backend
Browse files Browse the repository at this point in the history
  • Loading branch information
stone-w4tch3r committed Dec 12, 2024
1 parent d8fdbac commit 451ed0c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions server/.example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SWAGGER_BASIC_AUTH_USERNAME=your_swagger_username
SWAGGER_BASIC_AUTH_PASSWORD=your_swagger_password
BASIC_AUTH_USERNAME=your_basic_username
BASIC_AUTH_PASSWORD=your_basic_password
BASE_URL=/superchart-backend
3 changes: 2 additions & 1 deletion server/SuperchartBackend/EnvVars.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public static class EnvVars
public const string SwaggerBasicAuthPassword = "SWAGGER_BASIC_AUTH_PASSWORD";
public const string BasicAuthUsername = "BASIC_AUTH_USERNAME";
public const string BasicAuthPassword = "BASIC_AUTH_PASSWORD";
}
public const string BaseUrl = "BASE_URL";
}
9 changes: 8 additions & 1 deletion server/SuperchartBackend/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
builder.Services.AddScoped<SwaggerBasicAuthMiddleware>();

var app = builder.Build();

var baseUrl = Environment.GetEnvironmentVariable(EnvVars.BaseUrl)?.TrimEnd('/') ?? "";
if (!string.IsNullOrEmpty(baseUrl))
{
app.UsePathBase(baseUrl);
}

app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
Expand Down Expand Up @@ -67,4 +74,4 @@ static void ConfigureSwaggerUI(SwaggerUiSettings config)
config.Path = "/swagger";
config.DocumentPath = "/swagger/{documentName}/swagger.json";
config.DocExpansion = "list";
}
}
13 changes: 7 additions & 6 deletions server/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
version: '3.8'

services:
superchart-backend:
image: ghcr.io/stone-w4tch3r/superchart-backend:release
container_name: superchart-backend
pull_policy: always
ports:
- "5001:8080"
env_file:
- .env
environment:
- SWAGGER_BASIC_AUTH_USERNAME
- SWAGGER_BASIC_AUTH_PASSWORD
- BASIC_AUTH_USERNAME
- BASIC_AUTH_PASSWORD
- SWAGGER_BASIC_AUTH_USERNAME=${SWAGGER_BASIC_AUTH_USERNAME}
- SWAGGER_BASIC_AUTH_PASSWORD=${SWAGGER_BASIC_AUTH_PASSWORD}
- BASIC_AUTH_USERNAME=${BASIC_AUTH_USERNAME}
- BASIC_AUTH_PASSWORD=${BASIC_AUTH_PASSWORD}
- BASE_URL=${BASE_URL}

0 comments on commit 451ed0c

Please sign in to comment.