mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 11:12:18 +00:00
fix: register data providers for local preview
Adapt the preview middleware contribution from PR #324 to the extracted provider modules, including the existing OpenSky route.
This commit is contained in:
1 parent
276bb84904
commit
a0f07b752f
10 files changed
+64
-53
No files matched your search
@@ -13,9 +13,7 @@ export function adsbLolProxy() {
|
||||
let _cacheAt = 0;
|
||||
/** Response cache TTL (ms). */
|
||||
const CACHE_MS = 12000;
|
||||
return {
|
||||
name: 'adsblol-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/adsblol/mil', async (req, res) => {
|
||||
try {
|
||||
const now = Date.now();
|
||||
@@ -56,6 +54,10 @@ export function adsbLolProxy() {
|
||||
res.end(JSON.stringify({ error: 'ADS-B proxy error' }));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'adsblol-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -107,9 +107,7 @@ export function adsbdbProxy() {
|
||||
return inflight.get(ik);
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'adsbdb-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/adsbdb', async (req, res) => {
|
||||
await loadOnce();
|
||||
const send = (status, obj) => {
|
||||
@@ -125,20 +123,14 @@ export function adsbdbProxy() {
|
||||
if (!/^[A-Z0-9]{2,8}$/.test(cs))
|
||||
return send(400, { error: 'invalid callsign' });
|
||||
const data = await lookup('route', cs);
|
||||
return send(
|
||||
200,
|
||||
data ? { found: true, ...data } : { found: false },
|
||||
);
|
||||
return send(200, data ? { found: true, ...data } : { found: false });
|
||||
}
|
||||
if (kind === 'type') {
|
||||
const hex = String(rawKey || '').toLowerCase();
|
||||
if (!/^[0-9a-f]{6}$/.test(hex))
|
||||
return send(400, { error: 'invalid hex' });
|
||||
const data = await lookup('aircraft', hex);
|
||||
return send(
|
||||
200,
|
||||
data ? { found: true, ...data } : { found: false },
|
||||
);
|
||||
return send(200, data ? { found: true, ...data } : { found: false });
|
||||
}
|
||||
return send(404, { error: 'unknown endpoint' });
|
||||
} catch (err) {
|
||||
@@ -146,6 +138,10 @@ export function adsbdbProxy() {
|
||||
return send(500, { error: 'adsbdb proxy error' });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'adsbdb-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -348,9 +348,7 @@ function openSkySourceIsStale(sourceEpochMs, now = Date.now()) {
|
||||
* @returns {import('vite').Plugin}
|
||||
*/
|
||||
export function openSkyProxy() {
|
||||
return {
|
||||
name: 'opensky-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/opensky', async (req, res) => {
|
||||
try {
|
||||
const requestedMode = normalizeOpenSkyAuthMode(
|
||||
@@ -694,6 +692,10 @@ export function openSkyProxy() {
|
||||
res.end(JSON.stringify({ error: 'OpenSky proxy error' }));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'opensky-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -119,9 +119,7 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
name: 'cctv-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/cctv', async (req, res) => {
|
||||
try {
|
||||
const sources = await getCctvSources();
|
||||
@@ -297,8 +295,7 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
decodeURIComponent(url.pathname.replace('/frame/', '').trim()) ||
|
||||
'camera';
|
||||
const source = sourceById.get(cameraId);
|
||||
const label =
|
||||
url.searchParams.get('label') || source?.name || cameraId;
|
||||
const label = url.searchParams.get('label') || source?.name || cameraId;
|
||||
const city = url.searchParams.get('city') || source?.city || '';
|
||||
const lat = Number(url.searchParams.get('lat') || source?.lat);
|
||||
const lon = Number(url.searchParams.get('lon') || source?.lon);
|
||||
@@ -306,9 +303,7 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
url.searchParams.get('heading') || source?.headingDeg,
|
||||
);
|
||||
const fov = Number(url.searchParams.get('fov') || source?.fovDeg);
|
||||
const pitch = Number(
|
||||
url.searchParams.get('pitch') || source?.pitchDeg,
|
||||
);
|
||||
const pitch = Number(url.searchParams.get('pitch') || source?.pitchDeg);
|
||||
|
||||
// Only use server-registered upstream URLs — never accept client-supplied URLs
|
||||
// (prevents SSRF via ?upstream= query parameter)
|
||||
@@ -389,6 +384,10 @@ export function cctvProxy({ sourceRoot = process.cwd() } = {}) {
|
||||
res.end(JSON.stringify({ error: 'CCTV proxy error' }));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'cctv-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -167,9 +167,7 @@ export function firmsProxy() {
|
||||
return statusInflight;
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'firms-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/firms', async (req, res) => {
|
||||
const sendJson = (status, obj) => {
|
||||
if (res.headersSent) return;
|
||||
@@ -254,6 +252,10 @@ export function firmsProxy() {
|
||||
sendJson(500, { error: 'firms proxy error' });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'firms-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -21,9 +21,7 @@ const GBFS_PROXY_TIMEOUT_MS = 12000;
|
||||
* @returns {import('vite').Plugin}
|
||||
*/
|
||||
export function gbfsProxy() {
|
||||
return {
|
||||
name: 'gbfs-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/gbfs', async (req, res) => {
|
||||
try {
|
||||
if (req.method !== 'GET') {
|
||||
@@ -176,6 +174,10 @@ export function gbfsProxy() {
|
||||
res.end(JSON.stringify({ error: 'GBFS proxy error' }));
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'gbfs-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -764,9 +764,7 @@ export async function fetchOverpassPayload(body, maxResponseBytes = OVERPASS_MAX
|
||||
* @returns {import('vite').Plugin}
|
||||
*/
|
||||
function overpassProxy() {
|
||||
return {
|
||||
name: 'overpass-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/overpass', async (req, res) => {
|
||||
// Hoisted out of the try so the catch's serve-stale lookup can see it
|
||||
// (a body-read failure would otherwise hit an out-of-scope reference).
|
||||
@@ -896,7 +894,11 @@ function overpassProxy() {
|
||||
});
|
||||
|
||||
installRouteMiddleware(server.middlewares);
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'overpass-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -66,9 +66,7 @@ export function celestrakProxy() {
|
||||
return { at: Date.now(), body };
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'celestrak-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/celestrak', async (req, res) => {
|
||||
const group = String(req.url || '')
|
||||
.replace(/^\//, '')
|
||||
@@ -132,6 +130,10 @@ export function celestrakProxy() {
|
||||
send(500, 'celestrak proxy error', 'ERROR');
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'celestrak-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -131,9 +131,7 @@ export function terrainHeightsProxy() {
|
||||
return inflight.get(key);
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'terrain-heights-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/terrain/heights', async (req, res) => {
|
||||
const send = (status, bodyObj) => {
|
||||
if (res.headersSent) return;
|
||||
@@ -178,6 +176,10 @@ export function terrainHeightsProxy() {
|
||||
send(500, { error: 'terrain heights proxy error' });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'terrain-heights-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
@@ -144,9 +144,7 @@ export function tomtomProxy() {
|
||||
return buf;
|
||||
}
|
||||
|
||||
return {
|
||||
name: 'tomtom-proxy',
|
||||
configureServer(server) {
|
||||
const installMiddleware = (server) => {
|
||||
server.middlewares.use('/api/tomtom', async (req, res) => {
|
||||
// Sanitized responses only (proxy/security baseline): no upstream
|
||||
// error details, and never echo the key or the upstream URL.
|
||||
@@ -259,6 +257,10 @@ export function tomtomProxy() {
|
||||
sendJson(500, { error: 'proxy' });
|
||||
}
|
||||
});
|
||||
},
|
||||
};
|
||||
return {
|
||||
name: 'tomtom-proxy',
|
||||
configureServer: installMiddleware,
|
||||
configurePreviewServer: installMiddleware,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user