refactor: split terrain traffic fire and bike-share providers

This commit is contained in:
Sameh Khamis committed 2026-09-11 21:57:50 -07:00
1 parent 3ec3fe6822
commit f4054469d5
13 files changed
+1024 -797

No files matched your search

+52
View File
@@ -0,0 +1,52 @@
/** Allowlisted GBFS hostnames; wildcard *.publicbikesystem.net also accepted. */
const GBFS_ALLOWED_HOSTS = new Set([
'gbfs.lyft.com',
'gbfs.bluebikes.com',
'gbfs.bcycle.com',
'gbfs.biketownpdx.com',
'gbfs.cogobikeshare.com',
'austin.publicbikesystem.net',
'hon.publicbikesystem.net',
'chat.publicbikesystem.net',
]);
/**
* Check whether a hostname is in the GBFS allowlist.
*
* Also accepts any subdomain of publicbikesystem.net.
*
* @param {string} hostname
* @returns {boolean}
*/
export function isAllowedGbfsHost(hostname) {
const host = String(hostname || '').trim().toLowerCase();
if (!host) return false;
if (GBFS_ALLOWED_HOSTS.has(host)) return true;
return host.endsWith('.publicbikesystem.net');
}
/**
* Only allow station_information.json and station_status.json endpoints.
*
* @param {string} pathname
* @returns {boolean}
*/
export function isAllowedGbfsPath(pathname) {
return /\/station_(information|status)\.json$/i.test(String(pathname || ''));
}
/**
* Return an appropriate Cache-Control header for a GBFS endpoint.
*
* station_information is semi-static (5 min cache); station_status is
* real-time (no-store).
*
* @param {string} pathname
* @returns {string} Cache-Control header value.
*/
export function gbfsCacheControl(pathname) {
if (/\/station_information\.json$/i.test(String(pathname || ''))) {
return 'public, max-age=300';
}
return 'no-store';
}