Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

- adds https support

# 0.4.1 (12/04/2017)

- fixes type to be the same as the event names
Expand Down
24 changes: 20 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ npm install node-git-server
# Usage

```javascript
const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true,
authenticate: (type, repo, user, next) => {
Expand All @@ -38,14 +40,12 @@ const repos = new Server(path.resolve(__dirname, 'tmp'), {
const port = process.env.PORT || 7005;

repos.on('push', (push) => {
console.log('push ' + push.repo + '/' + push.commit
+ ' (' + push.branch + ')'
);
console.log(`push ${push.repo}/${push.commit} (${push.branch})`);
push.accept();
});

repos.on('fetch', (fetch) => {
console.log('fetch ' + fetch.commit);
console.log(`fetch ${fetch.commit}`);
fetch.accept();
});

Expand Down Expand Up @@ -73,6 +73,22 @@ To http://localhost:7005/beep
* [new branch] master -> master
```

## Example

Running the following command will start up a simple http server:

```
node example/index.js
```

If you want to try using https run the following

```
node example/index.js --https
```

> When running https with self-signed certs there are two ways to override the git-clients behavior using `git config http.sslVerify false` or `git config --global http.sslCAInfo /path/to/cert.pem`

For more information please visit the [docs](http://www.gabrielcsapo.com/node-git-server/code/index.html)

# Philosophy
Expand Down
12 changes: 12 additions & 0 deletions example/certificate.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-----BEGIN CERTIFICATE-----
MIIB0TCCAToCCQCvzaaNTZEFTDANBgkqhkiG9w0BAQUFADAtMQswCQYDVQQGEwJV
UzELMAkGA1UECAwCQ0ExETAPBgNVBAcMCFNhbiBKb3NlMB4XDTE3MTIwNzE5MTI0
NloXDTE4MDEwNjE5MTI0NlowLTELMAkGA1UEBhMCVVMxCzAJBgNVBAgMAkNBMREw
DwYDVQQHDAhTYW4gSm9zZTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEAplVm
UrhFbgb+g7gHDjfdTZUwqNnJ6AajytmqmzV7ceTeXKtKfNAN7i2DyFxf/IwQWoxs
0g7MOE8UP19GCInK0I5T9svvbtSVEfxrtGLMBY7qnojN7Q+DIjdvM7f/m5W8oNkQ
qb3EzkBKX6A5HobxKqTdu40IBLBkxa0faEmU84MCAwEAATANBgkqhkiG9w0BAQUF
AAOBgQAzN5VrWE0bFT/UZgUCHrR6h+EQRfGCybAq6MmS1hEoHkLyLPIjokcRWxFe
eufVyxesJaUiO6f3W34J2NoZK4NsEF931t/n12bB8Ku8H1tokNsyWqJns2Whj+bR
012osVh6ghdOvKD0yrnv6oLjMU51A8UKuxh51xoMThU0vBwvDg==
-----END CERTIFICATE-----
30 changes: 26 additions & 4 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
// You Can Use The Commands Below To Generate A Self Signed Certificate For Use With This Tutorial
// These Commands Require That You have 'openssl' installed on your system
// openssl genrsa -out privatekey.pem 1024
// openssl req -new -key privatekey.pem -out certrequest.csr
// openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

let type = 'http';

process.argv.slice(2).forEach((arg) => {
switch(arg) {
case 'https':
case '--https':
type = 'https';
break;
}
});

const fs = require('fs');
const path = require('path');

const Server = require('../');
Expand Down Expand Up @@ -28,14 +46,18 @@ repos.on('push', (push) => {
});

repos.on('fetch', (fetch) => {
console.log('username', fetch.username); // eslint-disable-line
console.log('fetch ' + fetch.repo + '/' + fetch.commit); // eslint-disable-line
console.log(`username ${fetch.username}`); // eslint-disable-line
console.log(`fetch ${fetch.repo}/${fetch.commit}`); // eslint-disable-line
fetch.accept();
});

repos.listen(port, (error) => {
repos.listen(port, {
type,
key: fs.readFileSync('./privatekey.pem'),
cert: fs.readFileSync('./certificate.pem')
}, (error) => {
if(error) return console.error(`failed to start git-server because of error ${error}`); // eslint-disable-line
console.log(`node-git-server running at http://localhost:${port}`); // eslint-disable-line
console.log(`node-git-server running at ${type}://localhost:${port}`); // eslint-disable-line
repos.list((err, result) => {
if (!result) {
console.log("No repositories available..."); // eslint-disable-line
Expand Down
15 changes: 15 additions & 0 deletions example/privatekey.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICWwIBAAKBgQCmVWZSuEVuBv6DuAcON91NlTCo2cnoBqPK2aqbNXtx5N5cq0p8
0A3uLYPIXF/8jBBajGzSDsw4TxQ/X0YIicrQjlP2y+9u1JUR/Gu0YswFjuqeiM3t
D4MiN28zt/+blbyg2RCpvcTOQEpfoDkehvEqpN27jQgEsGTFrR9oSZTzgwIDAQAB
AoGAb3gr6qOzY9ksF/nsQIsPtD6XLZFGzkgk3Hyi6QEeiWVn35KriJmlvEikWFIP
wZ/cFdKl2uAv3EyitRWUSYSOdcD+tri253WkwpKr8qEq3MKdEsQGZlPiO2MJpWsa
4vsy1bleUxqbB2TYIIXdjgD8TpTCh8sc8pVxEWEuEThxIIECQQDY9TSZkZHqsqpC
bK/VUpluj3coZJcczk64ZAdkWYlXfNpvgdT3ViPjpdEYeabzTP0xI7OHkx6fVLiS
87Y6EwWfAkEAxEQKhgj+saudBzl2EUQW5qntdJh3Fr+OLErSHb4M5E/nWvxW6il0
XWRE3b7KrikThPkwUtXPTBNGiZ7D1dvfnQJAHMLk5jbWETb+OzANX0pD7NQ4B7LO
FZOD/A3GrRbxjhePHZkokmFpAJTK02PNLhPWvNzuv9pRBO5GSbTlQ22iIQJAQiEy
8oqhVrgeRsrjr1mj5cCn07tzlOSiQOZM+dyJd3w81flkR64EGVupoJWisSACBbH4
yFBmcpmkEMa/8ZUOOQJAfAqyF5aCRh4MbPT7pCGSf0gckc3p6qISb1Zodh7GLSdb
f/VvQzhRG3MKnSl+ZQ+GQT+F+FeZl0/ZPjVRYG/Avw==
-----END RSA PRIVATE KEY-----
18 changes: 15 additions & 3 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const fs = require('fs');
const path = require('path');
const http = require('http');
const https = require('https');
const url = require('url');
const qs = require('querystring');
const httpDuplex = require('./http-duplex');
Expand Down Expand Up @@ -427,13 +428,24 @@ class Git extends EventEmitter {
* @method listen
* @memberof Git
* @param {Number} port - the port to start the server on
* @param {Object=} options - the options to add extended functionality to the server
* @param {String=} options.type - this is either https or http (the default is http)
* @param {Buffer|String=} options.key - the key file for the https server
* @param {Buffer|String=} options.cert - the cert file for the https server
* @param {Function} callback - the function to call when server is started or error has occured
*/
listen(port, callback) {
var self = this;
this.server = http.createServer(function(req, res) {
listen(port, options, callback) {
const self = this;
if(typeof options == 'function' || !options) {
callback = options;
options = { type: 'http' };
}
const createServer = options.type == 'http' ? http.createServer : https.createServer.bind(this, options);

this.server = createServer(function(req, res) {
self.handle(req, res);
});

this.server.listen(port, callback);
}
/**
Expand Down