Skip to content

Commit

Permalink
feat: send shapes directly without redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 28, 2023
1 parent bc0d36e commit 09e2f3d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/slimy-ravens-chew.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"cube-link": patch
---

Forward profiles directly from GitHub
15 changes: 14 additions & 1 deletion trifid/redirect.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-check
const { Readable } = require('stream')
const { fetchBuilder, MemoryCache } = require('node-fetch-cache')

/**
Expand Down Expand Up @@ -54,7 +55,19 @@ function factory () {
}
}
if (shapePath) {
return res.redirect(`https://raw.githubusercontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
return fetch(`https://raw.githubusercdontent.com/zazuko/cube-link/${versionPath}/validation/${shapePath}.ttl`)
.then(rawGithub => {
if (rawGithub.ok) {
res.set('Content-Type', 'text/turtle')
} else {
res.status(500)
}
Readable.fromWeb(rawGithub.body).pipe(res)
})
.catch((e) => {
res.status(502)
res.send(`Error fetching shape: ${e.message}`)
})
}
}

Expand Down

0 comments on commit 09e2f3d

Please sign in to comment.