repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
4646812
parent
7b8c79e
author
Eric Bower
date
2024-03-14 01:51:47 +0000 UTC
chore(imgs): cors headers
4 files changed,  +12, -4
M docker-compose.override.yml
+7, -0
 1@@ -11,6 +11,13 @@ services:
 2     ports:
 3       - "9000:9000"
 4       - "9001:9001"
 5+  registry:
 6+    env_file:
 7+      - .env.example
 8+    ports:
 9+      - "5000:5000"
10+    volumes:
11+      - ./imgs/registry.yml:/etc/docker/registry/config.yml
12   imgproxy:
13     env_file:
14       - .env.example
M imgs/ssh.go
+2, -0
 1@@ -23,6 +23,7 @@ import (
 2 	"github.com/charmbracelet/wish"
 3 	"github.com/picosh/pico/db"
 4 	"github.com/picosh/pico/db/postgres"
 5+	"github.com/picosh/pico/shared"
 6 	"github.com/picosh/ptun"
 7 )
 8 
 9@@ -121,6 +122,7 @@ func serveMux(ctx ssh.Context) http.Handler {
10 
11 	proxy.ModifyResponse = func(r *http.Response) error {
12 		log.Printf("%+v", r)
13+		shared.CorsHeaders(r.Header)
14 
15 		if slug != "" && r.Request.Method == http.MethodGet && strings.HasSuffix(r.Request.URL.Path, "_catalog") {
16 			b, err := io.ReadAll(r.Body)
M shared/api.go
+1, -2
 1@@ -12,8 +12,7 @@ import (
 2 	"github.com/picosh/pico/db"
 3 )
 4 
 5-func CorsHeaders(w http.ResponseWriter) {
 6-	headers := w.Header()
 7+func CorsHeaders(headers http.Header) {
 8 	headers.Add("Access-Control-Allow-Origin", "*")
 9 	headers.Add("Vary", "Origin")
10 	headers.Add("Vary", "Access-Control-Request-Method")
M shared/router.go
+2, -2
 1@@ -77,7 +77,7 @@ func CreateServeBasic(routes []Route, ctx context.Context) ServeFn {
 2 			matches := route.Regex.FindStringSubmatch(r.URL.Path)
 3 			if len(matches) > 0 {
 4 				if r.Method == "OPTIONS" && route.CorsEnabled {
 5-					CorsHeaders(w)
 6+					CorsHeaders(w.Header())
 7 					w.WriteHeader(http.StatusOK)
 8 					return
 9 				} else if r.Method != route.Method {
10@@ -86,7 +86,7 @@ func CreateServeBasic(routes []Route, ctx context.Context) ServeFn {
11 				}
12 
13 				if route.CorsEnabled {
14-					CorsHeaders(w)
15+					CorsHeaders(w.Header())
16 				}
17 
18 				finctx := context.WithValue(ctx, ctxKey{}, matches[1:])