npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ethicdevs/fastify-git-server

v1.6.1

Published

A Fastify plugin to easily make one/many Git repositories available for clone/fetch/push.

Downloads

18

Readme

fastify-git-server

NPM MIT License ci-main Average issue resolution time Number of open issues

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

// server.ts
// std
import { resolve } from "node:path";
// 3rd-party
import fastify from "fastify";
// app
import fastifyGitServer, { GitServer } from "@ethicdevs/fastify-git-server";

const HOST = process.env.HOST || "localhost";
const PORT = process.env.PORT != null ? parseInt(process.env.PORT, 10) : 4200;

async function main() {
  const server = fastify();

  server.register(fastifyGitServer, {
    // can be set to a path to git, else will directly call "git" from $PATH.
    gitExecutablePath: undefined,
    // if true, allows you to send message when client fetch/push to the git server.
    withSideBandMessages: true,
    // a custom resolver to resolve authorisation.
    async authorizationResolver(repoSlug, credentials) {
      if (repoSlug.toLowerCase() === "testorg/test-repo") {
        return (
          credentials.username === "test" && credentials.password === "test"
        );
      }
      return false;
    },
    // a custom resolver to resolve the repository metas.
    async repositoryResolver(repoSlug) {
      if (repoSlug !== "testorg/test-repo") {
        throw new Error("Cannot find such repository.");
      }
      return {
        authMode: GitServer.AuthMode.ALWAYS, // or PUSH_ONLY, or NEVER.
        gitRepositoryDir: resolve(
          "/home/git-server-user/repos/testorg/test-repo",
        ),
      };
    },
    onPush: (push) => {
      push.write("\n");
      push.write("Hey from the server 🖖\n\n");
      // to cancel transmission:
      // push.end("transmission complete 😎\n");
    },
  });

  server.listen(PORT, HOST, (err, listeningOnUrl) => {
    if (err != null) {
      console.error(`❌ Could not start server. Error: ${err.message}`);
    } else {
      console.log(`🚀 Server is up and running at: ${listeningOnUrl}`);
    }
  });

  return server;
}

main();

Run the server like so (or build/bundle it first), and enjoy!

$ ts-node server.ts
# Server is up and running at http://localhost:4200

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

Contributing

Contributions to this repository are welcome to everyone, please feel free to send a pull request for further review/discussion/merging/resolution. 👌

Run the tests

$ yarn test # run all tests
$ yarn test --coverage # get coverage in ./coverage/lcov-report/index.html
$ yarn test --coverage --watchAll # (dev) quick test iteration loop

Build the lib

$ yarn build
$ yarn typecheck # same but does not write to ./dist folder (only check types)

Credits

This library is a port of git-express, aimed at Fastify v3.x+. Original lib' has not received any update for more than 2 years now and has been released without any license...

It was a great source of inspiration for this library to be born, so thanks to the author for that piece of code! 😅

License

The MIT license.