Add configurable BasePath for subfolder hosting and update frontend base handling
This commit is contained in:
5
IIS.md
5
IIS.md
@@ -10,8 +10,9 @@
|
|||||||
- From repo root: `dotnet publish -c Release -o publish`
|
- From repo root: `dotnet publish -c Release -o publish`
|
||||||
- Copy `publish/` contents to site directory (keep `App_Data` writable by the app pool user).
|
- Copy `publish/` contents to site directory (keep `App_Data` writable by the app pool user).
|
||||||
- Set environment variables in web.config or IIS config:
|
- Set environment variables in web.config or IIS config:
|
||||||
- `ASPNETCORE_ENVIRONMENT=Production`
|
- `ASPNETCORE_ENVIRONMENT=Production`
|
||||||
- `ADMIN_PASSWORD=<your-secret>`
|
- `ADMIN_PASSWORD=<your-secret>`
|
||||||
|
- `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.
|
- Optional: enable stdout logging in `web.config` during troubleshooting only; disable afterward.
|
||||||
|
|
||||||
## Permissions
|
## Permissions
|
||||||
|
|||||||
@@ -38,6 +38,12 @@ builder.Services.ConfigureHttpJsonOptions(options =>
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
var basePath = builder.Configuration["BasePath"];
|
||||||
|
if (!string.IsNullOrWhiteSpace(basePath))
|
||||||
|
{
|
||||||
|
app.UsePathBase(basePath);
|
||||||
|
}
|
||||||
|
|
||||||
app.UseGlobalExceptionLogging();
|
app.UseGlobalExceptionLogging();
|
||||||
|
|
||||||
// Ensure database and migrations are applied on startup
|
// Ensure database and migrations are applied on startup
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
"BasePath": "",
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"Default": "Data Source=App_Data/gamelist.db"
|
"Default": "Data Source=App_Data/gamelist.db"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<title>CoopGameChooser</title>
|
<title>CoopGameChooser</title>
|
||||||
<link rel="stylesheet" href="styles.css">
|
<link rel="stylesheet" href="styles.css">
|
||||||
|
<!-- Optional: set data-app-base if served from a subfolder (e.g., /vote) -->
|
||||||
|
<meta name="app-base" content="">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="status-bar">
|
<div class="status-bar">
|
||||||
|
|||||||
@@ -1,7 +1,15 @@
|
|||||||
const defaultHeaders = { "Content-Type": "application/json" };
|
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 } = {}) {
|
async function request(path, { method = "GET", body, adminKey } = {}) {
|
||||||
const res = await fetch(path, {
|
const res = await fetch(withBase(path), {
|
||||||
method,
|
method,
|
||||||
headers: {
|
headers: {
|
||||||
...defaultHeaders,
|
...defaultHeaders,
|
||||||
|
|||||||
Reference in New Issue
Block a user