Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

fix: redirect to deno.land #1103

Merged
merged 1 commit into from
Jun 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions server/capi.dev/delegator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const shaAbbrevLength = 8
const rTagVersion = /^v(\d+\.\d+\.\d+(?:-.+)?)$/
const rPrVersion = /^pr:(\d+)$/
const rVersionedUrl = /^(?:\/@(.+?))?(\/.*)?$/
const rCapiPath = /^\/capi\/(.+)$/

const delegateeProjectId = "70eddd08-c9b0-4cb3-b100-8c6facf52f1e"
const githubApiBase = "https://api.github.com/repos/paritytech/capi/"
Expand All @@ -35,6 +36,12 @@ async function handler(request: Request) {
if (version !== normalizedVersion) {
return f.redirect(`/@${normalizedVersion}${path}`)
}
if (rTagVersion.test(version)) {
const match = rCapiPath.exec(path)
if (match) {
return f.redirect(`https://deno.land/x/capi@${version}/${match[1]}`)
}
}
const deploymentUrl = await getDeployment(sha)
return await fetch(new URL(path, deploymentUrl), {
method: request.method,
Expand Down