From 087e845b7b4346c6c88d3e36e4279737e76f840d Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Wed, 20 May 2026 12:03:28 -0600 Subject: [PATCH] it builds and shows the login page --- Makefile | 15 ++++++++++++++ cmd/server/main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++ go.sum | 2 ++ 3 files changed, 67 insertions(+) create mode 100644 Makefile create mode 100644 cmd/server/main.go create mode 100644 go.sum diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..7a7bb12 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +.DEFAULT_GOAL := build + +.PHONY:fmt vet build +fmt: + go fmt ./... + +vet: fmt + go vet ./... + +build: vet + cd web && pnpm run build + go build -v -o solopm-server ./cmd/server + +test: + go test ./tests/... \ No newline at end of file diff --git a/cmd/server/main.go b/cmd/server/main.go new file mode 100644 index 0000000..6df0828 --- /dev/null +++ b/cmd/server/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "html/template" + "log" + "net/http" + "os" + "path/filepath" + + "github.com/joho/godotenv" +) + +func handler(writer http.ResponseWriter, request *http.Request) { + templ := template.Must(template.ParseFiles("./web/dist/index.html")) + + templ.Execute(writer, nil) +} + +func main() { + err := godotenv.Load() + if err != nil { + log.Fatal("Error loading .env file") + } + + webDir := "./web/dist" + fs := http.FileServer(http.Dir(webDir)) + + http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) { + if request.URL.Path != "/" { + path := filepath.Join(webDir, filepath.Clean(request.URL.Path)) + _, err := os.Stat(path) + if err == nil { + fs.ServeHTTP(writer, request) + return + } + } + handler(writer, request) + }) + + port := os.Getenv("HTTP_PORT") + if port == "" { + port = "8080" + } + addr := ":" + port + fmt.Printf("Server listening on http://localhost%s\n", addr) + if err := http.ListenAndServe(addr, nil); err != nil { + log.Fatalf("server error: %v", err) + } +} diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..d61b19e --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= +github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=