node-git-server logonode-git-server

HTTPS

node-git-server can serve over HTTPS. Pass type: "https" to listen() along with your key and cert.

Generate a self-signed certificate

For local testing you can create a self-signed certificate with openssl:

openssl genrsa -out privatekey.pem 2048
openssl req -new -key privatekey.pem -out certrequest.csr
openssl x509 -req -in certrequest.csr -signkey privatekey.pem -out certificate.pem

Start an HTTPS server

server.js
import { Git } from "@batchfy/node-git-server"
import fs from "node:fs"
 
const repos = new Git("./repos", { autoCreate: true })
 
repos.on("fetch", (fetch) => fetch.accept())
repos.on("push", (push) => push.accept())
 
repos.listen(
    7005,
    {
        type: "https",
        key: fs.readFileSync("./privatekey.pem"),
        cert: fs.readFileSync("./certificate.pem"),
    },
    () => {
        console.log("node-git-server running at https://localhost:7005")
    }
)

Beyond type, key and cert, the options object accepts any Node https.createServer option (for example ca or passphrase).

Self-signed certificates and git

Git rejects self-signed certificates by default. For testing, either disable verification for a single repository:

git config http.sslVerify false

or point git at your certificate globally:

git config --global http.sslCAInfo /path/to/certificate.pem

In production, use a certificate from a trusted certificate authority instead.