Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 85540ce

Browse files
committed
fix(kueueviz): use wildcard for CORS allowed origins in development mode
Signed-off-by: Kay Yan <[email protected]>
1 parent 6c61dda commit 85540ce

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

cmd/kueueviz/backend/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ KUEUE_VIZ_PORT=8181 ./kueue_ws_app
4141

4242
## Variables
4343

44-
| Environment variables | Description | Default value |
45-
| --------------------- | ------------------------ | ------------- |
46-
| `KUEUE_VIZ_PORT` | Default application port | 8080 |
47-
| `GIN_MODE` | Gin mode | debug |
44+
45+
| Environment variables | Description | Default value |
46+
| -------------------------- | ------------------------------------ | ------------- |
47+
| `KUEUE_VIZ_PORT` | Default application port | 8080 |
48+
| `GIN_MODE` | Gin mode | debug |
49+
| `KUEUEVIZ_ALLOWED_ORIGINS` | Comma-separated list of CORS origins | `*` (dev only)|
4850

4951
## Endpoints
5052

cmd/kueueviz/backend/middleware/cors.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ import (
3131

3232
// validateOrigin validates and sanitizes a CORS origin URL
3333
func validateOrigin(origin string) (string, bool) {
34+
// Special case for wildcard origin
35+
if origin == "*" {
36+
return "*", true
37+
}
38+
3439
u, err := url.Parse(origin)
3540
if err != nil {
3641
return "", false
@@ -44,6 +49,7 @@ func validateOrigin(origin string) (string, bool) {
4449
return "", false
4550
}
4651

52+
// Only include scheme and host (which includes port if specified)
4753
cleanOrigin := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
4854
return cleanOrigin, true
4955
}
@@ -70,10 +76,7 @@ func ConfigureCORS() (cors.Config, error) {
7076
} else {
7177
// Default development origins (only in development mode)
7278
if gin.Mode() != gin.ReleaseMode {
73-
allowedOrigins = []string{
74-
"http://localhost:3000",
75-
"http://127.0.0.1:3000",
76-
}
79+
allowedOrigins = append(allowedOrigins, "*")
7780
log.Println("KUEUEVIZ_ALLOWED_ORIGINS not set, using default development origins")
7881
} else {
7982
log.Println("Production mode: KUEUEVIZ_ALLOWED_ORIGINS must be explicitly set")

0 commit comments

Comments
 (0)