summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo@mokhan.ca>2025-04-21 12:00:16 -0600
committermo khan <mo@mokhan.ca>2025-04-21 12:00:16 -0600
commit2854b695a0df016ef1a9c67303c15911b0ed4b72 (patch)
tree80d492014012b4b6d4e8e99fc30f0ee8afc43e51
parent49a8ef7441ac9355a7a8e4890f0a1c9004571f37 (diff)
refactor: provide the root dir as a parameter
-rw-r--r--app/app.go6
-rw-r--r--app/app_test.go6
-rw-r--r--cmd/sparkled/main.go4
3 files changed, 11 insertions, 5 deletions
diff --git a/app/app.go b/app/app.go
index 51979a4..8ccb71b 100644
--- a/app/app.go
+++ b/app/app.go
@@ -2,6 +2,7 @@ package app
import (
"net/http"
+ "path/filepath"
"github.com/rs/zerolog"
"github.com/xlgmokha/x/pkg/ioc"
@@ -15,7 +16,7 @@ import (
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/web/middleware"
)
-func New() http.Handler {
+func New(rootDir string) http.Handler {
mux := ioc.MustResolve[*http.ServeMux](ioc.Default)
mountable := []web.Mountable{
@@ -28,7 +29,8 @@ func New() http.Handler {
m.MountTo(mux)
}
- mux.Handle("GET /", http.FileServer(http.Dir("public")))
+ dir := http.Dir(filepath.Join(rootDir, "public"))
+ mux.Handle("GET /", http.FileServer(dir))
logger := ioc.MustResolve[*zerolog.Logger](ioc.Default)
oidc := ioc.MustResolve[*oidc.OpenID](ioc.Default)
diff --git a/app/app_test.go b/app/app_test.go
index 27f5f9c..bf706bc 100644
--- a/app/app_test.go
+++ b/app/app_test.go
@@ -3,18 +3,20 @@ package app
import (
"net/http"
"net/http/httptest"
+ "os"
"testing"
"github.com/stretchr/testify/assert"
+ "github.com/xlgmokha/x/pkg/x"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/pkg/test"
)
func TestApp(t *testing.T) {
t.Run("New", func(t *testing.T) {
- server := New()
+ wd := x.Must(os.Getwd())
+ server := New(wd + "/..")
t.Run("GET /index.html", func(t *testing.T) {
- t.Skip()
response := httptest.NewRecorder()
server.ServeHTTP(response, test.Request("GET", "/"))
diff --git a/cmd/sparkled/main.go b/cmd/sparkled/main.go
index 5eec970..7bec1b7 100644
--- a/cmd/sparkled/main.go
+++ b/cmd/sparkled/main.go
@@ -3,8 +3,10 @@ package main
import (
"log"
"net/http"
+ "os"
"github.com/xlgmokha/x/pkg/env"
+ "github.com/xlgmokha/x/pkg/x"
"gitlab.com/gitlab-org/software-supply-chain-security/authorization/sparkled/app"
)
@@ -14,6 +16,6 @@ func main() {
log.Fatal(http.ListenAndServe(
bindAddr,
- app.New(),
+ app.New(x.Must(os.Getwd())),
))
}