Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion apps/web/public/health/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,17 @@ self.addEventListener('install', (event) => {
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) => Promise.all(keys.filter((key) => key.startsWith('tleehealth-health-') && key !== CACHE).map((key) => caches.delete(key))))
.then(() => self.clients.claim()),
.then(() => self.clients.claim())
.then(() => {
setTimeout(() => {
self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clients) => {
for (const client of clients) {
const path = new URL(client.url).pathname;
if (path === '/health' || path.startsWith('/health/')) client.navigate('/health/').catch(() => {});
}
});
}, 0);
}),
);
});

Expand Down
10 changes: 9 additions & 1 deletion apps/web/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,15 @@ app.get('/health/', async (c) => {
app.get('/health/health.css', healthAsset('health.css', 'text/css; charset=utf-8'));
app.get('/health/health.js', healthAsset('health.js', 'text/javascript; charset=utf-8'));
app.get('/health/manifest.webmanifest', healthAsset('manifest.webmanifest', 'application/manifest+json'));
app.get('/health/sw.js', healthAsset('sw.js', 'text/javascript; charset=utf-8', { 'service-worker-allowed': '/health/' }));
// Keep the update script public so a logged-out installed copy can replace an
// older cache-first worker and clear its cached tracker shell.
app.get('/health/sw.js', (c) =>
c.body(pub('health/sw.js'), 200, {
'content-type': 'text/javascript; charset=utf-8',
'cache-control': 'no-cache',
'service-worker-allowed': '/health/',
}),
);

// The app: one shell for the team, patients and sign-in. It talks only to /api/v1.
// The shared profile fields (@profullstack/profile) ride in the shell as a
Expand Down
8 changes: 7 additions & 1 deletion test/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ describe('web', () => {
expect(page.status).toBe(302);
expect(page.headers.get('location')).toBe('/signin?next=%2Fhealth%2F');
}
for (const path of ['/health/health.css', '/health/health.js', '/health/manifest.webmanifest', '/health/sw.js']) {
for (const path of ['/health/health.css', '/health/health.js', '/health/manifest.webmanifest']) {
expect((await get(path)).status).toBe(401);
}
const worker = await get('/health/sw.js');
expect(worker.status).toBe(200);
expect(worker.headers.get('service-worker-allowed')).toBe('/health/');
const workerSource = await worker.text();
expect(workerSource).toContain('tleehealth-health-v4');
expect(workerSource).toContain("client.navigate('/health/')");
});
test('patient portal links to the free local health tracker', async () => {
const source = await (await get('/assets/app.js')).text();
Expand Down
Loading