mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
refactor: separate traffic and bikeshare components
This commit is contained in:
1 parent
3143d00c90
commit
903fe6ba37
45 files changed
+6159
-4363
No files matched your search
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user