diff --git a/IIS.md b/IIS.md index 4c7c2c5..14d1af7 100644 --- a/IIS.md +++ b/IIS.md @@ -10,8 +10,9 @@ - From repo root: `dotnet publish -c Release -o publish` - Copy `publish/` contents to site directory (keep `App_Data` writable by the app pool user). - Set environment variables in web.config or IIS config: - - `ASPNETCORE_ENVIRONMENT=Production` - - `ADMIN_PASSWORD=` +- `ASPNETCORE_ENVIRONMENT=Production` +- `ADMIN_PASSWORD=` +- `BasePath=/vote` (only if the site is under a subfolder; omit for root) - Optional: enable stdout logging in `web.config` during troubleshooting only; disable afterward. ## Permissions diff --git a/Program.cs b/Program.cs index 2d3ef8e..70779fd 100644 --- a/Program.cs +++ b/Program.cs @@ -38,6 +38,12 @@ builder.Services.ConfigureHttpJsonOptions(options => var app = builder.Build(); +var basePath = builder.Configuration["BasePath"]; +if (!string.IsNullOrWhiteSpace(basePath)) +{ + app.UsePathBase(basePath); +} + app.UseGlobalExceptionLogging(); // Ensure database and migrations are applied on startup diff --git a/appsettings.json b/appsettings.json index 3ffe25c..b2ba55a 100644 --- a/appsettings.json +++ b/appsettings.json @@ -6,6 +6,7 @@ } }, "AllowedHosts": "*", + "BasePath": "", "ConnectionStrings": { "Default": "Data Source=App_Data/gamelist.db" } diff --git a/wwwroot/index.html b/wwwroot/index.html index 6d54154..7139898 100644 --- a/wwwroot/index.html +++ b/wwwroot/index.html @@ -5,6 +5,8 @@ CoopGameChooser + +
diff --git a/wwwroot/js/api.js b/wwwroot/js/api.js index 018e7e6..bb633c3 100644 --- a/wwwroot/js/api.js +++ b/wwwroot/js/api.js @@ -1,7 +1,15 @@ const defaultHeaders = { "Content-Type": "application/json" }; +const metaBase = document.querySelector('meta[name="app-base"]')?.content || ""; +const autoBase = (() => { + const parts = window.location.pathname.split("/").filter(Boolean); + return parts.length ? `/${parts[0]}` : ""; +})(); +const basePath = metaBase || autoBase; +const withBase = (path) => `${basePath}${path}`; + async function request(path, { method = "GET", body, adminKey } = {}) { - const res = await fetch(path, { + const res = await fetch(withBase(path), { method, headers: { ...defaultHeaders,