npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-http-backend

v1.1.2

Published

serve a git repository over http

Downloads

10,008

Readme

git-http-backend

serve a git repository over http

Bring your own git-{receive,upload}-pack implementations or shell out to the system versions.

build status

example

var http = require('http');
var spawn = require('child_process').spawn;
var path = require('path');
var backend = require('git-http-backend');
var zlib = require('zlib');

var server = http.createServer(function (req, res) {
    var repo = req.url.split('/')[1];
    var dir = path.join(__dirname, 'repos', repo);
    var reqStream = req.headers['content-encoding'] == 'gzip' ? req.pipe(zlib.createGunzip()) : req;
    
    reqStream.pipe(backend(req.url, function (err, service) {
        if (err) return res.end(err + '\n');
        
        res.setHeader('content-type', service.type);
        console.log(service.action, repo, service.fields);
        
        var ps = spawn(service.cmd, service.args.concat(dir));
        ps.stdout.pipe(service.createStream()).pipe(ps.stdin);
        
    })).pipe(res);
});
server.listen(5000);

first create a repo with git init and run the server:

$ mkdir repos
$ git init repos/falafel.git --bare -q
$ node server.js &
[1] 10685

now you can push at http://localhost:5000/falafel.git:

$ cd ~/projects/node-falafel
$ git push http://localhost:5000/falafel.git master
info falafel.git {}
push falafel.git { name: 'master',
  head: 'c1cb53f6dd18cc814f42c4205e8c7efef007c171',
  last: '008a0000000000000000000000000000000000000000',
  ref: 'heads',
  branch: 'master' }
To http://localhost:5000/falafel.git
 * [new branch]      master -> master

and you can clone from http://localhost:5000/falafel.git too:

$ cd /tmp
$ git clone http://localhost:5000/falafel.git
Cloning into 'falafel'...
info falafel.git {}
pull falafel.git { head: 'c1cb53f6dd18cc814f42c4205e8c7efef007c171' }
remote: Counting objects: 247, done.
remote: Compressing objects: 100% (101/101), done.
remote: Total 247 (delta 139), reused 247 (delta 139)
Receiving objects: 100% (247/247), 55.40 KiB, done.
Resolving deltas: 100% (139/139), done.

methods

var backend = require('git-http-backend')

var b = backend(req.url, cb)

Return a duplex stream b from a request url req.url.

You should pipe an http request into b and pipe b into an http response, like this:

http.createServer(function (req, res) {
    var b = backend(req.url);
    req.pipe(b).pipe(res);
})

If you pass in a cb, it will register an errback for the 'service' and 'error' events.

var sb = b.createBand()

Return a writable side-band stream sb.

For info actions, you can write a response back to the user with this stream.

events

b.on('service', function (service) {})

When the service header metadata has been parsed, this event fires. service is a stream that outputs the request stream data from the remote git endpoint and expects the git-{receive,upload}-pack data as input. You should wire up the

service has these handy properties:

  • service.cmd - the git command name string
  • service.args - the arguments array that the git command expects
  • service.action - the type of request: 'info', 'tag', 'push', 'pull', or 'clone'
  • service.fields - the field data associated with the request action type
  • service.type - the content-type you should send for the response. Some git clients will not work if the proper content-type header hasn't been sent.

For 'info' actions, the service.fields is an empty object {}.

For 'pull' and 'clone' actions, the service.fields are:

  • service.fields.head - the commit hash of the requested HEAD

For 'push' actions, the service.fields are:

  • service.fields.last - the last commit in the commit payload range
  • service.fields.head - the first commit in the commit payload range
  • service.fields.branch - the branch name

For 'tag' actions, the service.fields are:

  • service.fields.last - the last commit in the commit payload range
  • service.fields.head - the first commit in the commit payload range
  • service.fields.tag - the tag text

b.on('error', function (err) {})

Handle errors here.

install

With npm do:

npm install git-http-backend

license

MIT