-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add devtools updates * add comment to explain the server route * make it an ISR route, handle errors --------- Co-authored-by: Rich Harris <[email protected]>
- Loading branch information
1 parent
670cf48
commit 6298f93
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
apps/svelte.dev/src/routes/devtools/updates.json/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { error, json } from '@sveltejs/kit'; | ||
import type { ServerlessConfig } from '@sveltejs/adapter-vercel'; | ||
|
||
export const config: ServerlessConfig = { | ||
isr: { | ||
expiration: 300 | ||
} | ||
}; | ||
|
||
// We manage FF extension by ourselves through GH releases and this acts as `update_url` | ||
// for our users to automatically update their extension when a new version is released | ||
// https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/browser_specific_settings#update_url | ||
export async function GET({ fetch }) { | ||
const response = await fetch('https://api.github.com/repos/sveltejs/svelte-devtools/tags'); | ||
|
||
if (!response.ok) { | ||
error(response.status); | ||
} | ||
|
||
const gh: Array<{ name: string }> = await response.json(); | ||
|
||
// v2.2.0 is the first version that has the Firefox extension | ||
const tags = gh.reverse().slice(gh.findIndex((t) => t.name === 'v2.2.0')); | ||
const base = 'https://github.com/sveltejs/svelte-devtools/releases/download'; | ||
return json({ | ||
addons: { | ||
'[email protected]': { | ||
updates: tags.map(({ name: tag }) => { | ||
return { | ||
version: tag, | ||
update_link: `${base}/${tag}/svelte-devtools.xpi`, | ||
applications: requirements[tag] && { gecko: requirements[tag] } | ||
}; | ||
}) | ||
} | ||
} | ||
}); | ||
} | ||
|
||
const requirements: Record<string, any> = { | ||
'v2.2.2': { strict_min_version: '121.0' } | ||
}; |