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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.6.0 (03/03/2019)

- Augments the authenticate function declaration to accept an object as the first argument and a callback for the second. This allows us to make changes without having to cause breaking changes.
- Adds the ability to introspect on the header (fixes #49)

# 0.5.1 (03/03/2019)

- bump dependencies
Expand Down
81 changes: 75 additions & 6 deletions docs/code/Git.html
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,13 @@ <h6>Properties</h6>



<td class="description last"><p>a function that has the following arguments (repo, username, password, next) and will be called when a request comes through if set</p>
<pre class="prettyprint source"><code> authenticate: (type, repo, username, password, next) => {
<td class="description last"><p>a function that has the following arguments ({ type, repo, username, password, headers }, next) and will be called when a request comes through if set</p>
<pre class="prettyprint source"><code> authenticate: ({ type, repo, username, password, headers }, next) => {
console.log(type, repo, username, password);
next();
}
// alternatively you can also pass authenticate a promise
authenticate: (type, repo, username, password, next) => {
authenticate: ({ type, repo, username, password, headers }, next) => {
console.log(type, repo, username, password);
return new Promise((resolve, reject) => {
if(username === 'foo') {
Expand Down Expand Up @@ -393,7 +393,7 @@ <h4 class="name" id=".close"><span class="type-signature">(static) </span>close<

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="git.js.html">git.js</a>, <a href="git.js.html#line451">line 451</a>
<a href="git.js.html">git.js</a>, <a href="git.js.html#line456">line 456</a>
</li></ul></dd>


Expand Down Expand Up @@ -444,6 +444,51 @@ <h4 class="name" id=".close"><span class="type-signature">(static) </span>close<





<h5>Parameters:</h5>


<table class="params">
<thead>
<tr>


<th>Type</th>





<th class="last">Description</th>
</tr>
</thead>

<tbody>


<tr>


<td class="type">


<span class="param-type">Promise</span>



</td>





<td class="description last"><p>will resolve or reject when the server closes or fails to close.</p></td>
</tr>


</tbody>
</table>



Expand Down Expand Up @@ -1106,7 +1151,7 @@ <h5>Parameters:</h5>



<h4 class="name" id=".listen"><span class="type-signature">(static) </span>listen<span class="signature">(port, options<span class="signature-attributes">opt</span>, callback)</span><span class="type-signature"></span></h4>
<h4 class="name" id=".listen"><span class="type-signature">(static) </span>listen<span class="signature">(port, options<span class="signature-attributes">opt</span>, callback)</span><span class="type-signature"> &rarr; {<a href="Git.html">Git</a>}</span></h4>



Expand All @@ -1118,7 +1163,7 @@ <h4 class="name" id=".listen"><span class="type-signature">(static) </span>liste

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="git.js.html">git.js</a>, <a href="git.js.html#line426">line 426</a>
<a href="git.js.html">git.js</a>, <a href="git.js.html#line429">line 429</a>
</li></ul></dd>


Expand Down Expand Up @@ -1435,6 +1480,30 @@ <h6>Properties</h6>



<h5>Returns:</h5>


<div class="param-desc">
<ul>
<li>the Git instance, useful for chaining</li>
</ul>
</div>



<dl class="param-type">
<dt>
Type
</dt>
<dd>

<span class="param-type"><a href="Git.html">Git</a></span>


</dd>
</dl>





Expand Down
6 changes: 3 additions & 3 deletions docs/code/Service.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ <h4 class="name" id="Service"><span class="type-signature"></span>new Service<sp

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line13">line 13</a>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line20">line 20</a>
</li></ul></dd>


Expand Down Expand Up @@ -1253,7 +1253,7 @@ <h4 class="name" id=".accept"><span class="type-signature">(static) </span>accep

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line153">line 153</a>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line198">line 198</a>
</li></ul></dd>


Expand Down Expand Up @@ -1337,7 +1337,7 @@ <h4 class="name" id=".reject"><span class="type-signature">(static) </span>rejec

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line136">line 136</a>
<a href="service.js.html">service.js</a>, <a href="service.js.html#line181">line 181</a>
</li></ul></dd>


Expand Down
20 changes: 15 additions & 5 deletions docs/code/git.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,14 @@ <h1 class="page-title">git.js</h1>
* @param {Object} options - options that can be applied on the new instance being created
* @param {Boolean=} options.autoCreate - By default, repository targets will be created if they don't exist. You can
disable that behavior with `options.autoCreate = true`
* @param {Function} options.authenticate - a function that has the following arguments (repo, username, password, next) and will be called when a request comes through if set
* @param {Function} options.authenticate - a function that has the following arguments ({ type, repo, username, password, headers }, next) and will be called when a request comes through if set
*
authenticate: (type, repo, username, password, next) => {
authenticate: ({ type, repo, username, password, headers }, next) => {
console.log(type, repo, username, password);
next();
}
// alternatively you can also pass authenticate a promise
authenticate: (type, repo, username, password, next) => {
authenticate: ({ type, repo, username, password, headers }, next) => {
console.log(type, repo, username, password);
return new Promise((resolve, reject) => {
if(username === 'foo') {
Expand Down Expand Up @@ -341,9 +341,12 @@ <h1 class="page-title">git.js</h1>
// check if the repo is authenticated
if(this.authenticate) {
const type = this.getType(service);
const promise = this.authenticate(type, repoName, basicAuth.bind(null, req, res), (error) => {
const headers = req.headers;
const user = basicAuth.bind(null, req, res);
const promise = this.authenticate({ type, repo: repoName, user, headers }, (error) => {
return next(error);
});

if(promise instanceof Promise) {
return promise
.then(next)
Expand Down Expand Up @@ -472,6 +475,7 @@ <h1 class="page-title">git.js</h1>
* @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
* @return {Git} - the Git instance, useful for chaining
*/
listen(port, options, callback) {
const self = this;
Expand All @@ -486,14 +490,20 @@ <h1 class="page-title">git.js</h1>
});

this.server.listen(port, callback);
return this;
}
/**
* closes the server instance
* @method close
* @memberof Git
* @param {Promise} - will resolve or reject when the server closes or fails to close.
*/
close() {
this.server.close();
return new Promise((resolve, reject) => {
this.server.close((err) => {
err ? reject(err) : resolve();
});
});
}
}

Expand Down
75 changes: 73 additions & 2 deletions docs/code/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Git.html"
<section class="readme">
<article><h1>node-git-server</h1><blockquote>
<p>🎡 A configurable git server written in Node.js</p>
</blockquote>
<blockquote>
<blockquote>
<p>there be 🐲 here! The API's and functionality are still be cemented, anything before a 1.0.0 release will be subject to change.</p>
</blockquote>
Expand All @@ -59,7 +61,76 @@ <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Git.html"
<a href="https://starbuck.gabrielcsapo.com/github/gabrielcsapo/node-git-server#info=devDependencies"><img src="https://starbuck.gabrielcsapo.com/badge/github/gabrielcsapo/node-git-server/dev-status.svg" alt="devDependency Status"></a>
<a href=""><img src="https://img.shields.io/npm/dt/node-git-server.svg" alt="npm"></a>
<a href=""><img src="https://img.shields.io/npm/dm/node-git-server.svg" alt="npm"></a></p>
<h1>Install</h1><pre class="prettyprint source"><code>npm install node-git-server</code></pre><h1>Usage</h1><pre class="prettyprint source lang-javascript"><code>const path = require('path');
<h1>Install</h1><pre class="prettyprint source"><code>npm install node-git-server</code></pre><h1>Usage</h1><h2>Simple</h2><pre class="prettyprint source lang-javascript"><code>const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true
});
const port = process.env.PORT || 7005;

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

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

repos.listen(port, () => {
console.log(`node-git-server running at http://localhost:${port}`)
});</code></pre><p>then start up the node-git-server server...</p>
<pre class="prettyprint source"><code>$ node example/index.js</code></pre><p>meanwhile...</p>
<pre class="prettyprint source"><code>$ git push http://localhost:7005/beep master
Counting objects: 356, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (133/133), done.
Writing objects: 100% (356/356), 46.20 KiB, done.
Total 356 (delta 210), reused 355 (delta 210)
To http://localhost:7005/beep
* [new branch] master -> master</code></pre><h2>Sending logs</h2><pre class="prettyprint source lang-javascript"><code>const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
autoCreate: true
});
const port = process.env.PORT || 7005;

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

repos.list((err, results) => {
push.log(' ');
push.log('Hey!');
push.log('Checkout these other repos:');
for(const repo of results) {
push.log(`- ${repo}`);
}
push.log(' ');
});

push.accept();
});

repos.listen(port, () => {
console.log(`node-git-server running at http://localhost:${port}`)
});</code></pre><p>then start up the node-git-server server...</p>
<pre class="prettyprint source"><code>$ node example/index.js</code></pre><p>meanwhile...</p>
<pre class="prettyprint source"><code>$ git push http://localhost:7005/beep master
Counting objects: 356, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (133/133), done.
Writing objects: 100% (356/356), 46.20 KiB, done.
Total 356 (delta 210), reused 355 (delta 210)
remote:
remote: Hey!
remote: Checkout these other repos:
remote: - test.git
remote:
To http://localhost:7005/test
77bb26e..22918d5 master -> master</code></pre><h3>Authentication</h3><pre class="prettyprint source lang-javascript"><code>const path = require('path');
const Server = require('node-git-server');

const repos = new Server(path.resolve(__dirname, 'tmp'), {
Expand Down Expand Up @@ -98,7 +169,7 @@ <h1>Install</h1><pre class="prettyprint source"><code>npm install node-git-serve
Writing objects: 100% (356/356), 46.20 KiB, done.
Total 356 (delta 210), reused 355 (delta 210)
To http://localhost:7005/beep
* [new branch] master -> master</code></pre><h2>Example</h2><p>Running the following command will start up a simple http server:</p>
* [new branch] master -> master</code></pre><h1>Example</h1><p>Running the following command will start up a simple http server:</p>
<pre class="prettyprint source"><code>node example/index.js</code></pre><p>If you want to try using https run the following</p>
<pre class="prettyprint source"><code>node example/index.js --https</code></pre><blockquote>
<p>When running https with self-signed certs there are two ways to override the git-clients behavior using <code>git config http.sslVerify false</code> or <code>git config --global http.sslCAInfo /path/to/cert.pem</code></p>
Expand Down
6 changes: 3 additions & 3 deletions docs/code/module-lib_util.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ <h4 class="name" id="~createAction"><span class="type-signature">(inner) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line164">line 164</a>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line171">line 171</a>
</li></ul></dd>


Expand Down Expand Up @@ -460,7 +460,7 @@ <h4 class="name" id="~infoResponse"><span class="type-signature">(inner) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line94">line 94</a>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line101">line 101</a>
</li></ul></dd>


Expand Down Expand Up @@ -974,7 +974,7 @@ <h4 class="name" id="~parseGitName"><span class="type-signature">(inner) </span>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line154">line 154</a>
<a href="util.js.html">util.js</a>, <a href="util.js.html#line161">line 161</a>
</li></ul></dd>


Expand Down
Loading