88 "net/http"
99 "net/http/httputil"
1010 "net/url"
11- "os"
1211 "slices"
1312 "strconv"
1413 "strings"
@@ -26,7 +25,7 @@ const (
2625 None AuthType = "None"
2726)
2827
29- func parseTypedQuery (key string , values []string ) interface {} {
28+ func parseTypedQuery (values []string ) interface {} {
3029 var result interface {}
3130
3231 raw := values [0 ]
@@ -80,12 +79,14 @@ func renderTemplate(name string, tmplStr string, data any) (string, error) {
8079 return buf .String (), nil
8180}
8281
83- func AuthMiddleware (next http.Handler ) http.Handler {
82+ func AuthMiddleware (next http.Handler , token string ) http.Handler {
8483 return http .HandlerFunc (func (w http.ResponseWriter , req * http.Request ) {
85- log .Info ("Request:" , req .Method , req .URL .Path )
84+ if token == "" {
85+ next .ServeHTTP (w , req )
86+ return
87+ }
8688
87- token := os .Getenv ("API_TOKEN" )
88- user := "api"
89+ log .Info ("Request:" , req .Method , req .URL .Path )
8990
9091 authHeader := req .Header .Get ("Authorization" )
9192
@@ -117,6 +118,8 @@ func AuthMiddleware(next http.Handler) http.Handler {
117118 basicAuth := string (basicAuthBody )
118119 basicAuthParams := strings .Split (basicAuth , ":" )
119120
121+ user := "api"
122+
120123 if basicAuthParams [0 ] == user && basicAuthParams [1 ] == token {
121124 success = true
122125 }
@@ -204,7 +207,7 @@ func TemplatingMiddleware(next http.Handler, VARIABLES map[string]string) http.H
204207 keyWithoutPrefix , found := strings .CutPrefix (key , "@" )
205208
206209 if found {
207- modifiedBodyData [keyWithoutPrefix ] = parseTypedQuery (key , value )
210+ modifiedBodyData [keyWithoutPrefix ] = parseTypedQuery (value )
208211
209212 modifiedQuery .Del (key )
210213 }
0 commit comments