Skip to content

Instantly share code, notes, and snippets.

Created March 24, 2023 16:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
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! 💖💕`);
Copy link

darobin commented Mar 24, 2023

This is a really dumb script that serves HTTP requests for /ipfs/f017c1114<git sha> as an IPFS gateway.

It's not graceful, it doesn't handle CIDs well, and it doesn't properly comply with gateway specs. But you could use it to serve git content in an IPFS context and a (tolerant) IPFS client would be able to interact with the content.

Copy link


Copy link

2color commented Nov 8, 2023


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