Connection unavailable
+MockAPI needs a connection to this instance. Check your network and that the server is running, then try again.
+No endpoint data is available offline. Changes are not queued or replayed.
+ Reconnect to MockAPI +diff --git a/.github/instructions/frontend.instructions.md b/.github/instructions/frontend.instructions.md index 299d394..b9ae2e2 100644 --- a/.github/instructions/frontend.instructions.md +++ b/.github/instructions/frontend.instructions.md @@ -52,6 +52,10 @@ applyTo: "src/MockAPI/wwwroot/**/*.{js,html,css},tests/{frontend,browser}/**/*.j - Route management requests through `dashboard-management.js`. Configuration commands pass an explicit captured ETag; editor drafts and confirmations keep their reviewed revision despite live updates. Keep the single-flight guard through the authoritative refresh, surface failures, and never automatically replay rejected writes. - Consume the synchronizer's explicit completed/failed/inactive refresh result at the command boundary. Background recovery may continue after failure, but a command must not treat a failed or interrupted refresh as successful. - Serve scripts and styles with private, content-validated caching; keep dashboard HTML and administrative data non-storable. Do not use immutable caching for unversioned asset URLs. +- Keep PWA installation assets under authenticated `/__mockapi/` routes. The root-scoped worker handles + only same-origin GET navigations to `/`, never API, mock, health, or asset requests. Use a generic + reconnect page only on network failure; preserve HTTP errors and never cache administrative content + or queue offline writes. Keep the worker URL stable and its updates revalidated. - Add JSDoc to every exported function, factory, and reusable exported value. Document parameters, return shapes, callbacks, lifecycle, side effects, thrown errors, and discriminated result variants where applicable. - Prefer reusable `@typedef` contracts for shared object shapes. Keep annotations specific enough to help editors and reviewers; do not use `Object` when a meaningful shape is known. - Keep shared endpoint, configuration, management-problem, and statistics wire shapes in `dashboard-core.js`, aligned with the backend's nullable and omitted fields. Keep named controller/lifecycle types in their owning modules and reuse shared contracts rather than duplicating payload shapes. diff --git a/docs/FEATURES.md b/docs/FEATURES.md index f28a1b0..bf14185 100644 --- a/docs/FEATURES.md +++ b/docs/FEATURES.md @@ -1,5 +1,28 @@ # Feature Readiness +## Installable dashboard + +The MockAPI dashboard is a progressive web app. Open your instance over HTTPS (or loopback HTTP +for development) and use your browser's **Install app** command. On iPhone or iPad, use Safari's +**Share > Add to Home Screen**. Availability and wording depend on the browser and operating system. +Installation opens the same instance in a standalone window; existing administrator authentication +still applies. Each origin identifies a separate installation. +The header displays the current instance's hostname, without protocol, port, or path, in both +browser tabs and installed app windows, including on mobile. + +The dashboard requires a live connection. After the first successful visit activates its service +worker, an offline launch shows a generic **Connection unavailable** page with a **Reconnect to +MockAPI** link. It stores no dashboard pages, endpoint definitions, statistics, credentials, or +request/response content in service-worker caches. Offline changes are not supported or queued. +Mock requests, management API calls, event streams, and health probes are never intercepted. +Live server errors and authentication challenges remain unchanged. + +The service worker updates through the browser's normal lifecycle; close existing dashboard windows +and reopen after a deployment to activate a waiting update. Browsers without service-worker support, +and non-loopback HTTP deployments, retain the ordinary live dashboard without offline support. +Disabling the dashboard also disables its manifest, icons, and service-worker routes; an already +installed app is not remotely uninstalled. + ## Azure Container Apps Express This matrix tracks the Azure Container Apps features MockAPI currently needs and their availability in the existing Consumption deployment versus Container Apps Express. Express is in preview, and its status is a documentation snapshot as of July 14, 2026. **Available** means the required capability is supported, **Partial** means it is not fully supported, and **In development** means MockAPI must not depend on it in an Express deployment yet. diff --git a/docs/PLAN.md b/docs/PLAN.md index f397758..ed4197d 100644 --- a/docs/PLAN.md +++ b/docs/PLAN.md @@ -316,6 +316,17 @@ Both Automatic and Columns when space allows must fall back to the single-column command groups wrap; preserve the saved preference when resizing. Cap the endpoint search field at 220px and align the collapse control with the first filter row when filters wrap. +### Installable dashboard + +Offer a web app manifest, local PNG icons, and a standalone launch at `/`. Register a stable, +root-scoped service worker only in secure contexts; it handles only same-origin GET dashboard +navigations at `/`, including query strings. All mock, management, health, and asset requests bypass +the worker. Preserve live HTTP errors and authentication challenges; only a failed network navigation +receives a generic, non-storable reconnect page. Never cache dashboard HTML, endpoint definitions, +statistics, credentials, or request/response content, and never queue or replay offline writes. +Keep all PWA assets under the authenticated, reserved `/__mockapi/` namespace and disable them +with the dashboard. Revalidate the worker on updates rather than using immutable caching. + ### Endpoint management - API-level descriptions are separate from operation descriptions. Use the existing first path segment diff --git a/src/MockAPI/Management/DashboardAssets.cs b/src/MockAPI/Management/DashboardAssets.cs index 6a8cff3..f866438 100644 --- a/src/MockAPI/Management/DashboardAssets.cs +++ b/src/MockAPI/Management/DashboardAssets.cs @@ -27,7 +27,8 @@ internal static void Map( string sourceName, string contentType, string version, - bool replaceVersionPlaceholder = false) + bool replaceVersionPlaceholder = false, + string? serviceWorkerScope = null) { var bytes = File.ReadAllBytes(Path.Combine(app.Environment.WebRootPath, sourceName)); if (replaceVersionPlaceholder) @@ -40,8 +41,14 @@ internal static void Map( var etag = new EntityTagHeaderValue($"\"{Convert.ToHexString(SHA256.HashData(bytes))}\""); app.MapGet(route, (HttpContext context) => { + if (serviceWorkerScope is not null) + { + // The dashboard lives at /; the worker handles only that navigation, never mock or API traffic. + context.Response.Headers["Service-Worker-Allowed"] = serviceWorkerScope; + } var requestedVersion = context.Request.Query["v"].ToString(); - context.Response.Headers.CacheControl = string.Equals(requestedVersion, version, StringComparison.Ordinal) + context.Response.Headers.CacheControl = serviceWorkerScope is null + && string.Equals(requestedVersion, version, StringComparison.Ordinal) ? "private, max-age=31536000, immutable" : "private, no-cache"; return Results.File(bytes, contentType, entityTag: etag); diff --git a/src/MockAPI/Program.cs b/src/MockAPI/Program.cs index fe88946..035a141 100644 --- a/src/MockAPI/Program.cs +++ b/src/MockAPI/Program.cs @@ -70,6 +70,10 @@ "dashboard-test-request.js", "dashboard-tutorial.js", "favicon.svg", + "manifest.webmanifest", + "service-worker.js", + "icon-192.png", + "icon-512.png", "openapi-logo.svg" ]; var assetVersion = DashboardAssets.CreateVersion(app.Environment.WebRootPath, dashboardAssetNames); @@ -104,6 +108,16 @@ DashboardAssets.Map(app, "/favicon.svg", "favicon.svg", "image/svg+xml", assetVersion); DashboardAssets.Map(app, "/favicon.ico", "favicon.svg", "image/svg+xml", assetVersion); DashboardAssets.Map(app, "/brand-mark.svg", "brand-mark.svg", "image/svg+xml", assetVersion); + DashboardAssets.Map(app, "/__mockapi/manifest.webmanifest", "manifest.webmanifest", "application/manifest+json", assetVersion); + DashboardAssets.Map(app, "/__mockapi/icon-192.png", "icon-192.png", "image/png", assetVersion); + DashboardAssets.Map(app, "/__mockapi/icon-512.png", "icon-512.png", "image/png", assetVersion); + DashboardAssets.Map( + app, + "/__mockapi/service-worker.js", + "service-worker.js", + "text/javascript; charset=utf-8", + assetVersion, + serviceWorkerScope: "/"); DashboardAssets.Map( app, "/__mockapi/openapi-logo.svg", diff --git a/src/MockAPI/wwwroot/app.css b/src/MockAPI/wwwroot/app.css index 55d7f27..30e3f18 100644 --- a/src/MockAPI/wwwroot/app.css +++ b/src/MockAPI/wwwroot/app.css @@ -169,11 +169,11 @@ button:disabled { /* Page header and configuration commands */ .app-header { - height: 64px; + min-height: 64px; display: flex; align-items: center; justify-content: space-between; - padding: 0 28px; + padding: 8px 28px; border-bottom: 1px solid var(--cp-border); background: var(--cp-bg-elevated); box-shadow: 0 3px 12px rgba(16, 36, 62, 0.06); @@ -213,11 +213,13 @@ button:disabled { } .brand-lockup { display: flex; + min-width: 0; align-items: center; gap: 12px; } .brand-lockup > div { display: grid; + min-width: 0; } .brand-lockup strong { font-size: 17px; @@ -225,9 +227,11 @@ button:disabled { .brand-lockup span { color: var(--cp-text-muted); font-size: 12px; + overflow-wrap: anywhere; } .brand-mark { display: block; + flex-shrink: 0; width: 42px; height: 34px; border-radius: 8px; @@ -2698,7 +2702,6 @@ html[data-theme="dark"] button:disabled { .header-api-security { margin-right: auto; } - .brand-lockup > div span, .connection-status { display: none; } diff --git a/src/MockAPI/wwwroot/app.js b/src/MockAPI/wwwroot/app.js index b545e6d..8255ea7 100644 --- a/src/MockAPI/wwwroot/app.js +++ b/src/MockAPI/wwwroot/app.js @@ -46,6 +46,7 @@ const elements = getDashboardElements(document, { "how-it-works-new-endpoint": "button", "import-button": "button", "import-file": "input", + "instance-domain": "span", "load-example-button": "button", "save-button": "button", "settings-button": "button", @@ -69,6 +70,8 @@ const elements = getDashboardElements(document, { "tutorial-title": "h2", }); +elements["instance-domain"].textContent = window.location.hostname; + const API = "/__mockapi/api"; // Access storage inside the store's guarded operations; the localStorage getter itself can throw. const dashboardPreferencesStore = createDashboardPreferencesStore({ @@ -696,3 +699,13 @@ pageEvents.listen(window, "pagehide", (event) => { dashboardSynchronizer.start().then(() => { tutorialController.startIfNeeded(window.location.search); }); + +if (window.isSecureContext && "serviceWorker" in navigator) { + // Keep the worker URL stable so deployments update one registration instead of accumulating workers. + navigator.serviceWorker + .register("/__mockapi/service-worker.js", { scope: "/", updateViaCache: "none" }) + .catch((error) => { + console.error("Dashboard offline support could not be registered.", error); + showToast("Dashboard offline support is unavailable. The live dashboard still works.", true); + }); +} diff --git a/src/MockAPI/wwwroot/icon-192.png b/src/MockAPI/wwwroot/icon-192.png new file mode 100644 index 0000000..a36aac8 Binary files /dev/null and b/src/MockAPI/wwwroot/icon-192.png differ diff --git a/src/MockAPI/wwwroot/icon-512.png b/src/MockAPI/wwwroot/icon-512.png new file mode 100644 index 0000000..88a6e99 Binary files /dev/null and b/src/MockAPI/wwwroot/icon-512.png differ diff --git a/src/MockAPI/wwwroot/index.html b/src/MockAPI/wwwroot/index.html index 9423e65..b54e398 100644 --- a/src/MockAPI/wwwroot/index.html +++ b/src/MockAPI/wwwroot/index.html @@ -40,6 +40,8 @@
MockAPI needs a connection to this instance. Check your network and that the server is running, then try again.
+No endpoint data is available offline. Changes are not queued or replayed.
+ Reconnect to MockAPI +