Created
January 17, 2024 07:40
-
-
Save jmezach/59967473bf0c363f777bf3e6a0563442 to your computer and use it in GitHub Desktop.
Backstage TechRadar from repository through proxy plugin
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
proxy: | |
endpoints: | |
'/tech-radar': | |
target: '<url-to-your-repo>' | |
pathRewrite: | |
'^/api/proxy/tech-radar/': '' | |
headers: | |
<whatever-is-needed-for-auth> |
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
import { DiscoveryApi, FetchApi } from "@backstage/core-plugin-api"; | |
import { RadarEntry, RadarEntrySnapshot, TechRadarApi, TechRadarLoaderResponse } from "@backstage/plugin-tech-radar"; | |
export class ProxyTechRadarApi implements TechRadarApi { | |
discoveryApi: DiscoveryApi; | |
fetchApi: FetchApi; | |
constructor({discoveryApi, fetchApi}: {discoveryApi: DiscoveryApi, fetchApi: FetchApi}) { | |
this.discoveryApi = discoveryApi; | |
this.fetchApi = fetchApi; | |
} | |
async load(id: string | undefined): Promise<TechRadarLoaderResponse> { | |
const proxyBaseUri = `${await this.discoveryApi.getBaseUrl('proxy')}/tech-radar${id ?? ""}`; | |
const techRadarUri = `${proxyBaseUri}/tech-radar.json`; | |
const response = await this.fetchApi.fetch(techRadarUri); | |
if (response.ok) { | |
const data = await response.json(); | |
const result: TechRadarLoaderResponse = { ...data, entries: [] }; | |
for (const quadrant of result.quadrants) { | |
const quadrantUri = `${proxyBaseUri}/${quadrant.id}.json`; | |
const quadrantResponse = await this.fetchApi.fetch(quadrantUri); | |
if (quadrantResponse.ok) { | |
const quadrantData = await quadrantResponse.json(); | |
result.entries.push( | |
...quadrantData.map((entry: RadarEntry) => ({ | |
...entry, | |
key: entry.id, | |
quadrant: quadrant.id, | |
timeline: entry.timeline.map((timeline: RadarEntrySnapshot) => ({ | |
...timeline, | |
date: new Date(timeline.date), | |
})), | |
})) | |
); | |
} | |
} | |
return result; | |
} else { | |
return { | |
quadrants: [], | |
rings: [], | |
entries: [] | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment