Skip to content

GitStarInc/nodegit-http

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Read-only GitHub-like HTTP API using nodegit.

While there are a few similar node projects out there, the goal of this project is to keep the implementation as simple and as hackable as possible.

Install & Usage

npm install -g nodegit
npm install -g nodegit-http

nodegit-http [--base=BASE_DIR] [--port=PORT] [--auth=AUTH_FILE]

nodegit-http serves any git repositories from the current directory, or that specified by the environment variable BASE_DIR. The assumed directory structure is as follows:

BASE_DIR/user/repo.git
BASE_DIR/anotheruser/theirrepo.git
...

Authorization

The binary takes a file path to an authorization node module. This module is expected to define a middleware function that the server will use for authorization:

modules.exports = function(req, res, next) {
  //E.g., allow : next();
  //E.g., deny  : next("Signal error");
};

The function is provided with the HTTP request (req), which you can use extract authorization information from; the response (res) can be used to directly produce an HTTP response; and, next should be used to to pass control to the next middleware. See express.js middleware for more information.

Using as a library

You can also use nodegit-http as a library

var githttp = require('nodegit-http');
var app  = githttp({ baseDir: ...
                   , authorize: function (req, res, next) {
                     ...
                   });

app.listen(PORT);
console.log('Serving repos from %s on port %d', BASE_DIR, PORT);

The module requires a base directory, specified by the property baseDir of the options argument. The app will use the specified 'authorize' function for authorization, if provided. Otherwise it will just use allow all requests.

Finally, it returns an app object which is a express.js Application, that you can use as usual. The module will use the app provided in the (property app) options object; this is useful if you wish to define that should match first.

API

The server exposes several routes, similar to the GitHub-API. All responses are JSON.

About

Read-only GitHub-like HTTP API atop nodegit using express

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published