Files
worldmonitor/api/version.js
Elie Habib bdd8743a26 refactor: dedupe edge api json response assembly (#1702)
* refactor: dedupe edge api json response assembly

* refactor: expand jsonResponse helper to all edge functions

Roll out jsonResponse() from _json-response.js to 16 files (14 handlers
+ 2 shared helpers), eliminating 55 instances of the
new Response(JSON.stringify(...)) boilerplate.

Only exception: health.js uses JSON.stringify(body, null, indent) for
pretty-print mode, which is incompatible with the helper signature.

Replaced local jsonResponse/json() definitions in contact.js,
register-interest.js, and cache-purge.js with the shared import.
2026-03-16 11:52:56 +04:00

28 lines
809 B
JavaScript

import { fetchLatestRelease } from './_github-release.js';
import { jsonResponse } from './_json-response.js';
export const config = { runtime: 'edge' };
export default async function handler() {
try {
const release = await fetchLatestRelease('WorldMonitor-Version-Check');
if (!release) {
return jsonResponse({ error: 'upstream' }, 502);
}
const tag = release.tag_name ?? '';
const version = tag.replace(/^v/, '');
return jsonResponse({
version,
tag,
url: release.html_url,
prerelease: release.prerelease ?? false,
}, 200, {
'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=60, stale-if-error=3600',
'Access-Control-Allow-Origin': '*',
});
} catch {
return jsonResponse({ error: 'fetch_failed' }, 502);
}
}