@@ -33,6 +33,7 @@ import (
33
33
"github.com/cortexlabs/cortex/pkg/operator/resources/job/taskapi"
34
34
"github.com/cortexlabs/cortex/pkg/operator/resources/realtimeapi"
35
35
"github.com/cortexlabs/cortex/pkg/types/userconfig"
36
+ "github.com/gorilla/handlers"
36
37
"github.com/gorilla/mux"
37
38
"github.com/prometheus/client_golang/prometheus/promhttp"
38
39
)
@@ -127,5 +128,16 @@ func main() {
127
128
routerWithAuth .HandleFunc ("/logs/{apiName}" , endpoints .ReadLogs )
128
129
129
130
operatorLogger .Info ("Running on port " + _operatorPortStr )
130
- operatorLogger .Fatal (http .ListenAndServe (":" + _operatorPortStr , router ))
131
+
132
+ // inspired by our nginx config
133
+ corsOptions := []handlers.CORSOption {
134
+ handlers .AllowedOrigins ([]string {"*" }),
135
+ // custom headers are not supported currently, since "*" is not supported in AllowedHeaders(); here are some common ones:
136
+ handlers .AllowedHeaders ([]string {"Content-Type" , "X-Requested-With" , "User-Agent" , "Accept" , "Accept-Language" , "Content-Language" , "Origin" }),
137
+ handlers .AllowedMethods ([]string {"GET" , "HEAD" , "POST" , "PUT" , "OPTIONS" }),
138
+ handlers .ExposedHeaders ([]string {"Content-Length" , "Content-Range" }),
139
+ handlers .AllowCredentials (),
140
+ }
141
+
142
+ operatorLogger .Fatal (http .ListenAndServe (":" + _operatorPortStr , handlers .CORS (corsOptions ... )(router )))
131
143
}
0 commit comments