Skip to content

Latest commit

 

History

History
67 lines (48 loc) · 3.07 KB

README.md

File metadata and controls

67 lines (48 loc) · 3.07 KB

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.