diff --git a/.changeset/slimy-ravens-chew.md b/.changeset/slimy-ravens-chew.md new file mode 100644 index 0000000..d3f8b52 --- /dev/null +++ b/.changeset/slimy-ravens-chew.md @@ -0,0 +1,5 @@ +--- +"cube-link": patch +--- + +Forward profiles directly from GitHub diff --git a/trifid/redirect.js b/trifid/redirect.js index 2384a54..45796d2 100644 --- a/trifid/redirect.js +++ b/trifid/redirect.js @@ -1,4 +1,5 @@ // @ts-check +const { Readable } = require('stream') const { fetchBuilder, MemoryCache } = require('node-fetch-cache') /** @@ -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}`) + }) } }