fix(web): манифест PWA отдаётся с правильным типом

Go определяет .webmanifest как text/plain, из-за чего браузер мог отказаться
ставить приложение: тип задаём явно вместе с js/css/svg.
This commit is contained in:
2026-09-21 19:45:25 +03:00
parent 5afcfee744
commit dd4432452c
6 changed files with 217 additions and 1 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

+29
View File
@@ -0,0 +1,29 @@
{
"name": "glchat",
"short_name": "glchat",
"description": "glchat — self-hosted платформа общения: серверы, комнаты, голос и файлы",
"lang": "ru",
"dir": "ltr",
"start_url": "/app",
"scope": "/",
"display": "standalone",
"display_override": ["window-controls-overlay", "standalone"],
"orientation": "any",
"background_color": "#1a1b1e",
"theme_color": "#1a1b1e",
"categories": ["social", "communication"],
"icons": [
{ "src": "/icons/icon-192.png", "sizes": "192x192", "type": "image/png" },
{ "src": "/icons/icon-512.png", "sizes": "512x512", "type": "image/png" },
{
"src": "/icons/maskable-512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "maskable"
}
],
"shortcuts": [
{ "name": "Друзья", "url": "/app/friends" },
{ "name": "Настройки", "url": "/settings/account/profile" }
]
}
+60
View File
@@ -0,0 +1,60 @@
<!doctype html>
<html lang="ru" data-theme="dark">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="color-scheme" content="dark light" />
<title>glchat — нет сети</title>
<style>
:root {
color-scheme: dark;
}
body {
margin: 0;
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: #1a1b1e;
color: #f2f3f5;
font:
16px/1.5 system-ui,
-apple-system,
'Segoe UI',
sans-serif;
}
main {
max-width: 28rem;
padding: 2rem;
text-align: center;
}
h1 {
margin: 0 0 0.5rem;
font-size: 1.25rem;
}
p {
margin: 0 0 1.25rem;
color: #a3a6ad;
}
button {
padding: 0.5rem 1rem;
border: 1px solid #3a3c42;
border-radius: 0.5rem;
background: #26282d;
color: inherit;
font: inherit;
cursor: pointer;
}
</style>
</head>
<body>
<main>
<h1>Нет соединения</h1>
<p>
glchat не смог связаться с сервером. Проверьте сеть — как только связь вернётся, приложение
откроется само.
</p>
<button type="button" onclick="location.reload()">Повторить</button>
</main>
</body>
</html>
+91
View File
@@ -0,0 +1,91 @@
/*
* Сервис-воркер glchat (AGENT.md, Фаза 5): офлайн-заглушка и кэш статики.
*
* Правила простые и безопасные:
* - навигация — сеть, при ошибке офлайн-страница (данные всегда свежие);
* - собранная статика `/assets/*` (хешированные имена) — из кэша;
* - API, шлюз и файлы никогда не кэшируются: это приватные данные.
*/
const VERSION = 'glchat-v1';
const OFFLINE_URL = '/offline.html';
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(VERSION).then((cache) => cache.addAll([OFFLINE_URL, '/manifest.webmanifest'])),
);
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches
.keys()
.then((keys) =>
Promise.all(keys.filter((key) => key !== VERSION).map((key) => caches.delete(key))),
)
.then(() => self.clients.claim()),
);
});
/** Приватные запросы: их нельзя ни кэшировать, ни отдавать из кэша. */
function isPrivate(url) {
return (
url.pathname.startsWith('/api/') ||
url.pathname.startsWith('/files/') ||
url.pathname.startsWith('/gateway') ||
url.pathname.startsWith('/rtc')
);
}
self.addEventListener('fetch', (event) => {
const request = event.request;
if (request.method !== 'GET') {
return;
}
const url = new URL(request.url);
if (url.origin !== self.location.origin || isPrivate(url)) {
return;
}
if (request.mode === 'navigate') {
event.respondWith(
fetch(request).catch(() =>
caches.match(request).then((cached) => cached ?? caches.match(OFFLINE_URL)),
),
);
return;
}
if (url.pathname.startsWith('/assets/')) {
event.respondWith(
caches.match(request).then(
(cached) =>
cached ??
fetch(request).then((response) => {
if (response.ok) {
const copy = response.clone();
void caches.open(VERSION).then((cache) => cache.put(request, copy));
}
return response;
}),
),
);
return;
}
// Иконки, манифест и прочая статика: сеть, при недоступности — кэш.
event.respondWith(
fetch(request)
.then((response) => {
if (
response.ok &&
(url.pathname.startsWith('/icons/') || url.pathname === '/manifest.webmanifest')
) {
const copy = response.clone();
void caches.open(VERSION).then((cache) => cache.put(request, copy));
}
return response;
})
.catch(() => caches.match(request).then((cached) => cached ?? Response.error())),
);
});