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.pemStart an HTTPS server
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 falseor point git at your certificate globally:
git config --global http.sslCAInfo /path/to/certificate.pemIn production, use a certificate from a trusted certificate authority instead.