Skip to content

Instantly share code, notes, and snippets.

@darobin
Created March 24, 2023 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darobin/9c9984586dcb133f384d3fd05f3a0bb9 to your computer and use it in GitHub Desktop.
Save darobin/9c9984586dcb133f384d3fd05f3a0bb9 to your computer and use it in GitHub Desktop.
A very dumb and non-compliant IPFS gateway to git
// 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! 💖💕`);
});
@autonome
Copy link

SHIP IT!

@2color
Copy link

2color commented Nov 8, 2023

Neat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment