Skip to content

Commit

Permalink
fix: Cache in-memory Helia Version Info
Browse files Browse the repository at this point in the history
Signed-off-by: Nishant Arora <[email protected]>
  • Loading branch information
whizzzkid committed Oct 4, 2023
1 parent 8ce2220 commit 1783c52
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/heliaServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface IRouteHandler {

class HeliaServer {
private heliaFetch!: HeliaFetch
private heliaVersionInfo!: {Version: string, Commit: string}
public routes: IRouteEntry[]
public isReady: Promise<void>

Expand Down Expand Up @@ -145,16 +146,20 @@ class HeliaServer {
await this.isReady

try {
const { default: packageJson } = await import('../../node_modules/helia/package.json', {
assert: { type: 'json' }
})
const { version: heliaVersionString } = packageJson

const ghResp = await (await fetch(HELIA_RELEASE_INFO_API(heliaVersionString))).json()
response.json({
Version: heliaVersionString,
Commit: ghResp.object.sha.slice(0, 7)
})
if (this.heliaVersionInfo === undefined) {
const { default: packageJson } = await import('../../node_modules/helia/package.json', {
assert: { type: 'json' }
})
const { version: heliaVersionString } = packageJson

const ghResp = await (await fetch(HELIA_RELEASE_INFO_API(heliaVersionString))).json()
this.heliaVersionInfo = {
Version: heliaVersionString,
Commit: ghResp.object.sha.slice(0, 7)
}
}

response.json(this.heliaVersionInfo)
} catch (error) {
response.status(500).end()
}
Expand Down

0 comments on commit 1783c52

Please sign in to comment.