Add git server

This commit is contained in:
orosmatthew 2023-05-01 13:26:49 -04:00
parent 03f55baf1c
commit b103cef169
7 changed files with 80 additions and 7 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
repo

View File

@ -1 +1,2 @@
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public" DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
GIT_REPO_DIR="./repo"

22
web/package-lock.json generated
View File

@ -14,6 +14,7 @@
"diff": "^5.1.0", "diff": "^5.1.0",
"diff2html": "^3.4.35", "diff2html": "^3.4.35",
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
"node-git-server": "^1.0.0",
"prisma": "^4.13.0", "prisma": "^4.13.0",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"zod": "^3.21.4" "zod": "^3.21.4"
@ -23,6 +24,7 @@
"@sveltejs/kit": "^1.15.9", "@sveltejs/kit": "^1.15.9",
"@types/bootstrap": "^5.2.6", "@types/bootstrap": "^5.2.6",
"@types/diff": "^5.0.3", "@types/diff": "^5.0.3",
"@types/node": "^18.16.3",
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.1", "@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1", "@typescript-eslint/parser": "^5.59.1",
@ -811,6 +813,12 @@
"integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==",
"dev": true "dev": true
}, },
"node_modules/@types/node": {
"version": "18.16.3",
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.16.3.tgz",
"integrity": "sha512-OPs5WnnT1xkCBiuQrZA4+YAV4HEJejmHneyraIaxsbev5yCEr6KMwINNFP9wQeFIw8FWcoTqF3vQsa5CDaI+8Q==",
"devOptional": true
},
"node_modules/@types/pug": { "node_modules/@types/pug": {
"version": "2.0.6", "version": "2.0.6",
"resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.6.tgz", "resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.6.tgz",
@ -2338,6 +2346,15 @@
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==", "integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
"dev": true "dev": true
}, },
"node_modules/node-git-server": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-git-server/-/node-git-server-1.0.0.tgz",
"integrity": "sha512-LdAEExF4N6/RIuAdJe16l1U5OZrw5M1U7B4C4O2PiRVImyaPNTFeTHlj46vGgpjthvrK7z43JKcIPc4r6+j0fA==",
"hasInstallScript": true,
"dependencies": {
"through": "^2.3.8"
}
},
"node_modules/nopt": { "node_modules/nopt": {
"version": "1.0.10", "version": "1.0.10",
"resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz",
@ -3000,6 +3017,11 @@
"integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==", "integrity": "sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==",
"dev": true "dev": true
}, },
"node_modules/through": {
"version": "2.3.8",
"resolved": "https://registry.npmjs.org/through/-/through-2.3.8.tgz",
"integrity": "sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg=="
},
"node_modules/tiny-glob": { "node_modules/tiny-glob": {
"version": "0.2.9", "version": "0.2.9",
"resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz", "resolved": "https://registry.npmjs.org/tiny-glob/-/tiny-glob-0.2.9.tgz",

View File

@ -16,6 +16,7 @@
"@sveltejs/kit": "^1.15.9", "@sveltejs/kit": "^1.15.9",
"@types/bootstrap": "^5.2.6", "@types/bootstrap": "^5.2.6",
"@types/diff": "^5.0.3", "@types/diff": "^5.0.3",
"@types/node": "^18.16.3",
"@types/uuid": "^9.0.1", "@types/uuid": "^9.0.1",
"@typescript-eslint/eslint-plugin": "^5.59.1", "@typescript-eslint/eslint-plugin": "^5.59.1",
"@typescript-eslint/parser": "^5.59.1", "@typescript-eslint/parser": "^5.59.1",
@ -38,6 +39,7 @@
"diff": "^5.1.0", "diff": "^5.1.0",
"diff2html": "^3.4.35", "diff2html": "^3.4.35",
"highlight.js": "^11.8.0", "highlight.js": "^11.8.0",
"node-git-server": "^1.0.0",
"prisma": "^4.13.0", "prisma": "^4.13.0",
"uuid": "^9.0.0", "uuid": "^9.0.0",
"zod": "^3.21.4" "zod": "^3.21.4"

View File

@ -1,6 +1,9 @@
import { redirect, type Handle } from '@sveltejs/kit'; import { redirect, type Handle } from '@sveltejs/kit';
import { db } from '$lib/server/prisma'; import { db } from '$lib/server/prisma';
import type { Session } from '@prisma/client'; import type { Session } from '@prisma/client';
import { startGitServer } from '$lib/server/gitserver';
startGitServer();
const sessionExpireMilliseconds = 1000 * 60 * 60 * 24; // 24 hours const sessionExpireMilliseconds = 1000 * 60 * 60 * 24; // 24 hours

View File

@ -0,0 +1,49 @@
import { error } from 'console';
import { Git } from 'node-git-server';
import { join } from 'path';
let gitRunning = false;
export function startGitServer() {
if (!gitRunning) {
const port =
!process.env.GIT_PORT || isNaN(parseInt(process.env.GIT_PORT))
? 7006
: parseInt(process.env.GIT_PORT);
if (!process.env.GIT_REPO_DIR) {
throw error('GIT_REPO_DIR not specified in .env');
}
const repoDir = process.env.GIT_REPO_DIR;
const repos = new Git(join(repoDir), {
autoCreate: false,
authenticate: ({ type, user, repo }, next) => {
if (type == 'push') {
console.log(repo);
user((username, password) => {
console.log(username, password);
next();
});
} else {
next();
}
}
});
repos.on('push', (push) => {
console.log(`push ${push.repo}/${push.commit} ( ${push.branch} )`);
push.accept();
});
repos.on('fetch', (fetch) => {
console.log(`fetch ${fetch.commit}`);
fetch.accept();
});
repos.listen(port, { type: 'http' }, () => {
console.log(`node-git-server running at http://localhost:${port}`);
gitRunning = true;
});
}
}

View File

@ -3,15 +3,10 @@ import { vitePreprocess } from '@sveltejs/kit/vite';
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
// Consult https://kit.svelte.dev/docs/integrations#preprocessors
// for more information about preprocessors
preprocess: vitePreprocess(), preprocess: vitePreprocess(),
kit: { kit: {
// adapter-auto only supports some environments, see https://kit.svelte.dev/docs/adapter-auto for a list. adapter: adapter(),
// If your environment is not supported or you settled on a specific environment, switch out the adapter.
// See https://kit.svelte.dev/docs/adapters for more information about adapters.
adapter: adapter()
} }
}; };