diff --git a/public/client.js b/public/client.js index a12fa26..86b9f58 100644 --- a/public/client.js +++ b/public/client.js @@ -289,14 +289,18 @@ .off('show.bs.dropdown.westgateUnread') .on('show.bs.dropdown.westgateUnread', '.wg-topbar [component="unread"]', function () { const menuEl = this.querySelector('[data-wg-unread-menu]'); - require(['api'], function (api) { - api.get('/unread', {}, function (err, data) { - if (err) { - renderUnreadMenu(menuEl, []); - return; - } - renderUnreadMenu(menuEl, data && data.topics); - }); + const relativePath = (window.config && window.config.relative_path) || ''; + fetch(relativePath + '/api/unread', { + headers: { accept: 'application/json' }, + }).then(function (res) { + if (!res.ok) { + throw new Error('unread fetch failed: ' + res.status); + } + return res.json(); + }).then(function (data) { + renderUnreadMenu(menuEl, data && data.topics); + }).catch(function () { + renderUnreadMenu(menuEl, []); }); }); } diff --git a/tests/unread-drawer-client.test.js b/tests/unread-drawer-client.test.js index 8e82d62..04aad59 100644 --- a/tests/unread-drawer-client.test.js +++ b/tests/unread-drawer-client.test.js @@ -11,7 +11,7 @@ assert( 'client.js should fetch unread topics when the unread dropdown opens' ); assert( - client.includes("api.get('/unread'"), + client.includes("'/api/unread'"), 'client.js should load the unread list from the /unread API' ); assert(