Created
March 24, 2023 16:13
-
-
Save darobin/9c9984586dcb133f384d3fd05f3a0bb9 to your computer and use it in GitHub Desktop.
A very dumb and non-compliant IPFS gateway to git
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
// Adin (paraphrased): "If I take a script and wrap git so it prefixes its hashes with f017c1114, | |
// do we have IPFS yet?" | |
import express from 'express'; | |
import process from 'process'; | |
import { join } from 'path'; | |
// path to a .git | |
const gitDir = join(process.argv[2], 'objects'); | |
const app = express(); | |
app.get('/ipfs/:cid', (req, res) => { | |
const { cid } = req.params; | |
if (!/^f017c1114/.test(cid) || !/^\w+$/.test(cid)) return res.status(404).send('Not found'); | |
const gitPath = join(gitDir, cid.replace(/^f017c1114/, '').replace(/^(..)/, '$1/')); | |
console.warn(`Fetching ${gitPath}`); | |
res.sendFile(gitPath, (err) => { | |
if (err) res.status(404).send('Not found'); | |
}); | |
}); | |
app.listen(8877, () => { | |
console.warn(`IPFS Gitway up on http://localhost:8877! 💖💕`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Neat!