-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
executable file
·48 lines (35 loc) · 1.44 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env node
'use strict';
var fs = require('fs');
var docopt = require('docopt').docopt;
var githttp = require('./lib/nodegit-http');
var usage = _toString(function() {/*
Simple git http server.
Usage:
$program [--base=BASE_DIR] [--port=PORT] [--auth=AUTH_FILE]
$program -h | --help
$program -v | --version
Options:
--port=PORT Port to listen on [default: 3000]
--base=BASE_DIR Base directory for user repositories
--auth=AUTH_FILE Filepath of authorization module
-h --help Show this
-v --version Get version
*/});
var cli = docopt(usage, {version: require('./package.json').version});
var BASE_DIR = fs.realpathSync(cli['--base'] || process.env.BASE_DIR ||
process.env.npm_config_BASE_DIR || __dirname);
var PORT = parseInt(cli['--port'] || process.env.PORT ||
process.env.npm_config_PORT || '3000', 10);
var AUTH_FILE = cli['--auth'] || process.env.AUTH_FILE ||
process.env.npm_config_AUTH_FILE;
var app = githttp({ baseDir: BASE_DIR
, authorize: AUTH_FILE ? require(AUTH_FILE) : undefined });
app.listen(PORT);
console.log('Serving repos from %s on port %d', BASE_DIR, PORT);
// Helper function
function _toString(f) {
var program = __filename.split('/').slice(-1)[0];
var lines = f.toString().replace(/\$program/g, program).split('\n');
return lines.splice(1, lines.length - 2).join('\n');
}