refactor: separate traffic and bikeshare components

This commit is contained in:
Sameh Khamis committed 2026-09-13 14:10:38 -07:00
1 parent 3143d00c90
commit 903fe6ba37
45 files changed
+6159 -4363

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
/** Read a GBFS station document through the existing bounded server proxy. */
export function createBikeshareSource({
fetchImpl = (...args) => globalThis.fetch(...args),
} = {}) {
return {
async getStations(upstreamUrl, { signal } = {}) {
const url = new URL(upstreamUrl);
if (url.protocol !== 'https:' || url.username || url.password || url.hash)
throw new TypeError('A public HTTPS GBFS URL is required');
signal?.throwIfAborted();
const response = await fetchImpl(
'/api/gbfs?url=' + encodeURIComponent(url.href),
{ method: 'GET', headers: { Accept: 'application/json' }, signal },
);
if (!response.ok) throw new Error('GBFS HTTP ' + response.status);
const payload = await response.json();
signal?.throwIfAborted();
if (!payload || typeof payload !== 'object')
throw new Error('Malformed GBFS payload');
return payload;
},
};
}