forked from gabrielcsapo/node-git-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
76 lines (65 loc) · 2.23 KB
/
index.js
File metadata and controls
76 lines (65 loc) · 2.23 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// 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('../');
const port = process.env.PORT || 7005;
const repos = new Server(path.normalize(path.resolve(__dirname, 'tmp')), {
autoCreate: true,
authenticate: (type, repo, user, next) => {
console.log(type, repo); // eslint-disable-line
if(type == 'push') {
user((username, password) => {
console.log(username, password); // eslint-disable-line
next();
});
} else {
next();
}
}
});
repos.on('push', (push) => {
console.log(`push ${push.repo} / ${push.commit} ( ${push.branch} )`); // eslint-disable-line
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.on('fetch', (fetch) => {
console.log(`username ${fetch.username}`); // eslint-disable-line
console.log(`fetch ${fetch.repo}/${fetch.commit}`); // eslint-disable-line
fetch.accept();
});
repos.listen(port, {
type,
key: fs.readFileSync(path.resolve(__dirname, 'privatekey.pem')),
cert: fs.readFileSync(path.resolve(__dirname, '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 ${type}://localhost:${port}`); // eslint-disable-line
repos.list((err, result) => {
if (!result) {
console.log("No repositories available..."); // eslint-disable-line
} else {
console.log(result); // eslint-disable-line
}
});
});