Skip to content

Commit f80310a

Browse files
authored
Add CORS configuration (#69)
1 parent da9e15f commit f80310a

5 files changed

Lines changed: 14 additions & 1 deletion

File tree

config/development.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
enableUi: true
22
enableOpenApi: true
3+
cors:
4+
allowOrigins:
5+
- http://localhost:3000
36
auth:
47
enabled: false
58
providers:

docker/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ docker run \
3030
-e TEMPORAL_AUTH_CALLBACK_URL=https://xxxx.com:8080/auth/sso/callback \ -- Auth callback url
3131
-e TEMPORAL_ENABLE_UI=true \ -- Serve UI
3232
-e TEMPORAL_ENABLE_OPENAPI=true \ -- Serve Open API UI
33+
-e TEMPORAL_CORS_ORIGINS=http://localhost:3000 \ -- Allow CORS origins
3334
temporalio/ui:<tag>
3435
```

docker/config_template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ port: {{ default .Env.TEMPORAL_UI_PORT "8080" }}
33
uiRootPath: {{ default .Env.TEMPORAL_UI_ROOT_PATH "/" }}
44
enableUi: {{ default .Env.TEMPORAL_ENABLE_UI "true" }}
55
enableOpenApi: {{ default .Env.TEMPORAL_ENABLE_OPENAPI "true" }}
6+
cors:
7+
allowOrigins:
8+
# override framework's default that allows all origins "*"
9+
- {{ default .Env.TEMPORAL_CORS_ORIGINS "http://localhost:8080" }}
610
auth:
711
enabled: {{ default .Env.TEMPORAL_AUTH_ENABLED "false" }}
812
providers:

server/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ type (
3737
Auth Auth `yaml:"auth"`
3838
EnableUI bool `yaml:"enableUi"`
3939
EnableOpenAPI bool `yaml:"enableOpenApi"`
40+
CORS CORS `yaml:"cors"`
41+
}
42+
43+
CORS struct {
44+
AllowOrigins []string `yaml:"allowOrigins"`
4045
}
4146

4247
Auth struct {

server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func NewServer(opts ...server_options.ServerOption) *Server {
7373
e.Use(middleware.Logger())
7474
e.Use(middleware.Recover())
7575
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
76-
AllowOrigins: []string{"http://localhost:3000", "https://localhost:3000", "http://localhost:8080"},
76+
AllowOrigins: serverOpts.Config.CORS.AllowOrigins,
7777
AllowHeaders: []string{echo.HeaderOrigin, echo.HeaderContentType, echo.HeaderAccept},
7878
}))
7979
e.Use(session.Middleware(sessions.NewCookieStore(

0 commit comments

Comments
 (0)