@@ -33,6 +33,7 @@ import (
3333 "github.com/cortexlabs/cortex/pkg/operator/resources/job/taskapi"
3434 "github.com/cortexlabs/cortex/pkg/operator/resources/realtimeapi"
3535 "github.com/cortexlabs/cortex/pkg/types/userconfig"
36+ "github.com/gorilla/handlers"
3637 "github.com/gorilla/mux"
3738 "github.com/prometheus/client_golang/prometheus/promhttp"
3839)
@@ -127,5 +128,16 @@ func main() {
127128 routerWithAuth .HandleFunc ("/logs/{apiName}" , endpoints .ReadLogs )
128129
129130 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 )))
131143}
0 commit comments