fastify-git-server
A Fastify plugin to easily make one/many Git repositories available for clone/fetch/push.
Installation
$ yarn add @ethicdevs/fastify-git-server
# or
$ npm i @ethicdevs/fastify-git-server
Usage
import fastify from "fastify";
import fastifyGitServer, { GitServer } from "@ethicdevs/fastify-git-server";
(function main() {
const server = fastify();
server.register(fastifyGitServer, {
gitExecutablePath: undefined,
authorize(repoSlug: string, credentials: GitServer.AuthCredentials) {
if (repoSlug.toLowerCase() === "testorg/test-repo") {
return cred.username === "test" && cred.password === "test";
}
return false;
},
repositoryResolver(
repoSlug: string,
): PromiseLike<GitServer.RepositoryResolverResult> {
return {
authMode: GitServer.AuthMode.ALWAYS,
gitRepositoryDir: resolve(
"/home/git-server-user/repos/testorg/test-repo",
),
};
},
});
server.listen("localhost", 4200, () => {
console.log(`Server is up and running at http://localhost:4200`);
});
})();
Run the server like so (or build/bundle it first), and enjoy!
$ ts-node server.ts
Now you can easily git clone/fetch/push to the repository assuming you pass the
right credentials set for the right repository.
$ git clone http://localhost:4200/testorg/test-repo.git
$ cd test-repo/
$ git fetch
$ git pull --rebase
$ echo "Today is: $(date)" >> ReadMe.md
$ git commit -am 'docs(readme): add the date of today'
$ git push
License
The MIT license.