Closed netlander closed 6 years ago
Could you paste the code you are running?
It's the code straight out from example/index.js
found in the repo. I have created my own certificates and the created repos can be found in examples/tmp
// 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, result) => {
console.log(result); // eslint-disable-line
});
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('./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 ${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
}
});
});
Works on my machine. These are the steps I followed:
/tmp/a/index.js
).const Server = require('../');
to const Server = require('node-git-server');
.npm install node-git-server
.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
.tmp
and enter it (/tmp/a/tmp
).asdf
and enter it (/tmp/a/tmp/asdf
).git init --bare
./tmp/a
.node index.js
.It ran without errors.
Now, in another terminal:
/tmp/b
) and enter it.git clone http://localhost:7005/asdf
(It should be OK so far.)asdf
directory.echo a>a.txt
-- Run: git add *
-- Run: git commit -m a
-- Run: git push
with random username and password.
(It should be OK so far.)rm -rf /tmp/b/asdf
git clone http://localhost:7005/asdf
.cat a.txt
Everything seems to be working fine. Try it, and if it doesn't work, the problem probably has to do with your NodeJS installation.
Thank you so much @jlxip for helping @netlander with his issue! Really thorough instructions. @netlander did these help? If so I think we could add these to the docs so that anyone else facing this issue can refer back to this for help.
@jlxip Thanks for the instructions. @gabrielcsapo Just trying these now... Will update later (probably tomorrow).
The above instructions didn't work for me. In fact I tried something similar before opening this issue but when I try to do npm i node-git-server
inside the repo, I get the following error, which is the same error I got when I tried the above steps.
npm ERR! code ENOSELF
npm ERR! Refusing to install package with name "node-git-server" under a package
npm ERR! also called "node-git-server". Did you name your project the same
npm ERR! as the dependency you're installing?
npm ERR!
npm ERR! For more information, see:
npm ERR! <https://docs.npmjs.com/cli/install#limitations-of-npms-install-algorithm>
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\yaseen\AppData\Roaming\npm-cache\_logs\2018-03-06T13_34_56_108Z-debug.log
@gabrielcsapo You need to amend the documentation to make it clear that users can use the given example either in a fresh node project or an existing one but outside of this repo.
Edit:
I did get this working on a new node project.
When you install from source it is simply npm install
.
@netlander so the documentation did work after installing in a npm project?
When running a fresh install on Win 10, the commit goes well but I get the above error after trying to access the repo:
The error coming from the server:
Any pointers as to what is going wrong?
Thanks