Skip to content

Commit 0a0c75b

Browse files
committed
🏗️ Test setting cors on bucket
Signed-off-by: grnd-alt <[email protected]>
1 parent c4219bf commit 0a0c75b

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

docker-compose.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ services:
3636
image: minio/minio:latest
3737
ports:
3838
- "9000:9000"
39+
- "9001:9001"
3940
- "45199:45199"
4041
environment:
4142
MINIO_ROOT_USER: minioadmin
4243
VIRTUAL_PORT: 9000
4344
MINIO_ROOT_PASSWORD: minioadmin
44-
command: server /data
45+
command: server /data --console-address ":9001"
4546
volumes:
4647
- minio_data:/data
4748
networks:

services/file_service.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"time"
88

99
"github.com/minio/minio-go/v7"
10+
"github.com/minio/minio-go/v7/pkg/cors"
1011
"github.com/minio/minio-go/v7/pkg/credentials"
1112
)
1213

@@ -40,6 +41,19 @@ func InitFileService(url string, accessKey string, secretKey string, bucketName
4041
return nil, err
4142
}
4243
}
44+
test := minioClient.SetBucketCors(context.Background(), bucketName, cors.NewConfig([]cors.Rule{
45+
{
46+
MaxAgeSeconds: 3600,
47+
AllowedHeader: []string{"*"},
48+
AllowedMethod: []string{"GET"}, // Allow GET requests
49+
AllowedOrigin: []string{"*"}, // Allow any origin (use specific one in prod)
50+
ExposeHeader: []string{"ETag", "Content-Type"},
51+
},
52+
}))
53+
if test != nil {
54+
fmt.Println("Failed to set bucket CORS:", test)
55+
}
56+
4357
return &FileService{
4458
minioClient: minioClient,
4559
bucketName: bucketName,

0 commit comments

Comments
 (0)