fix(website): fetch release version at runtime with asset validation
Move release version resolution from build-time (vite.config.ts) to runtime (server function on Cloudflare Workers). The server function fetches GitHub releases, filters out prereleases/drafts, and only returns a version that has all required assets (Mac DMG, Linux AppImage, Windows exe). Uses Cloudflare's cf.cacheEverything with a 60s TTL to avoid hitting GitHub on every request. This fixes a race condition where the website would deploy and show download links for a new release before the desktop build assets were actually uploaded, resulting in 404s for users.
This commit is contained in:
@@ -28,27 +28,8 @@ const sitemapPages = [
|
||||
path: routePath,
|
||||
}));
|
||||
|
||||
async function fetchLatestReleaseVersion(): Promise<string | undefined> {
|
||||
try {
|
||||
const res = await fetch(
|
||||
"https://api.github.com/repos/getpaseo/paseo/releases/latest",
|
||||
{ headers: { Accept: "application/vnd.github+json" }, signal: AbortSignal.timeout(5000) },
|
||||
);
|
||||
if (!res.ok) return undefined;
|
||||
const data = (await res.json()) as { tag_name: string };
|
||||
return data.tag_name.replace(/^v/, "");
|
||||
} catch {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export default defineConfig(async (): Promise<UserConfig> => {
|
||||
const latestVersion = await fetchLatestReleaseVersion();
|
||||
|
||||
export default defineConfig((): UserConfig => {
|
||||
return {
|
||||
define: {
|
||||
...(latestVersion && { __DESKTOP_VERSION__: JSON.stringify(latestVersion) }),
|
||||
},
|
||||
server: {
|
||||
port: 8082,
|
||||
fs: {
|
||||
|
||||
Reference in New Issue
Block a user