From 339313fd01c404d8d04c7dda0e66c2fadb22a0dd Mon Sep 17 00:00:00 2001 From: Gibheer Date: Wed, 30 Oct 2024 15:59:52 +0100 Subject: reduce the code from cgit purpose built to cgi generic --- main.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index e3d8d91..a2decee 100644 --- a/main.go +++ b/main.go @@ -1,19 +1,26 @@ package main import ( + "flag" "log" "net/http" "net/http/cgi" + "strings" ) func main() { + path := flag.String("path", "", "Path to the cgi binary") + dir := flag.String("dir", "", "set a different working directory from the base path of 'path'") + env := flag.String("env", "", "set environment variables for the CGI process") + prefix := flag.String("uri-prefix", "/", "set the URL prefix when the CGI process is hosted in a sub directory") + flag.Parse() + forwarder := &cgi.Handler{ - Path: "/usr/lib/cgit/cgit.cgi", - Root: "/", - Env: []string{"CGIT_CONFIG=cgitrc"}, - Dir: "/home/gibheer/projects/", + Path: *path, + Root: *prefix, + Env: strings.Split(*env, ","), + Dir: *dir, } - http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("/usr/share/webapps/cgit/")))) http.Handle("/", forwarder) log.Fatalf("server stopped working: %s", http.ListenAndServe(":8080", nil)) } -- cgit v1.2.3-70-g09d2