From 500b2f26a1c7466d2903069555098312a4e3e93c Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 3 May 2024 12:27:52 -0700 Subject: [PATCH 1/3] Add CORS support --- go.mod | 1 + go.sum | 2 ++ server/server.go | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 35ba48675..4ab8d4955 100644 --- a/go.mod +++ b/go.mod @@ -59,6 +59,7 @@ require ( github.com/prometheus/client_model v0.6.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/r3labs/sse/v2 v2.10.0 // indirect + github.com/rs/cors v1.11.0 // indirect github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/tidwall/gjson v1.17.1 // indirect diff --git a/go.sum b/go.sum index 7fcd2a0fe..0b93f5246 100644 --- a/go.sum +++ b/go.sum @@ -157,6 +157,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= +github.com/rs/cors v1.11.0 h1:0B9GE/r9Bc2UxRMMtymBkHTenPkHDv0CW4Y98GBY+po= +github.com/rs/cors v1.11.0/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/rs/xid v1.5.0 h1:mKX4bl4iPYJtEIxp6CYiUuLQ/8DYMoz0PUdtGgMFRVc= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0= diff --git a/server/server.go b/server/server.go index f528de502..b2da297d4 100644 --- a/server/server.go +++ b/server/server.go @@ -19,6 +19,8 @@ import ( "hmruntime/logger" "hmruntime/metrics" "hmruntime/utils" + + "github.com/rs/cors" ) // shutdownTimeout is the time to wait for the server to shutdown gracefully. @@ -84,7 +86,8 @@ func GetHandlerMux() http.Handler { // Also register the health endpoint, un-instrumented. mux.HandleFunc("/health", healthHandler) - return mux + // Add CORS support to all endpoints. + return cors.Default().Handler(mux) } func healthHandler(w http.ResponseWriter, r *http.Request) { From a76334e96f7c9610797d1c3e35b62239e9313da2 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 3 May 2024 12:30:00 -0700 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 594d75c34..acfe31803 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,21 @@ # Change Log -# 2024-05-02 - Version 0.6.3 +## UNRELEASED + +- Add CORS support to all endpoints [#171](https://github.com/gohypermode/runtime/pull/171) + +## 2024-05-02 - Version 0.6.3 - Update metrics collection to remove labels [#163](https://github.com/gohypermode/runtime/pull/163) - Add environment and version to health endpoint [#164](https://github.com/gohypermode/runtime/pull/164) - Capture function execution duration in metrics [#165](https://github.com/gohypermode/runtime/pull/165) -# 2024-04-29 - Version 0.6.2 +## 2024-04-29 - Version 0.6.2 - Traces and non-user errors are now sent to Sentry [#158](https://github.com/gohypermode/runtime/issues/158) - Fix OpenAI text generation [#161](https://github.com/gohypermode/runtime/issues/161) -# 2024-04-26 - Version 0.6.1 +## 2024-04-26 - Version 0.6.1 - Fix GraphQL error when resulting data contains a nested null field [#150](https://github.com/gohypermode/runtime/issues/150) - Fix GraphQL error when resolving `__typename` fields; also add `HYPERMODE_TRACE` debugging flag [#151](https://github.com/gohypermode/runtime/issues/151) @@ -20,7 +24,7 @@ - Note: It works correctly for system-generated and user-generated (`ctrl-C`) terminations, but [not when debugging in VS Code](https://github.com/golang/vscode-go/issues/120). - Add version awareness [#155](https://github.com/gohypermode/runtime/issues/155) -# 2024-04-25 - Version 0.6.0 +## 2024-04-25 - Version 0.6.0 Baseline for the change log. From 1dde7b9ba5da68b981bf8fcd3b43a24d4454a8d1 Mon Sep 17 00:00:00 2001 From: Matt Johnson-Pint Date: Fri, 3 May 2024 12:32:24 -0700 Subject: [PATCH 3/3] tidy --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 4ab8d4955..7b1f9501d 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/joho/godotenv v1.5.1 github.com/prometheus/client_golang v1.19.0 github.com/prometheus/common v0.48.0 + github.com/rs/cors v1.11.0 github.com/rs/xid v1.5.0 github.com/rs/zerolog v1.32.0 github.com/stretchr/testify v1.9.0 @@ -59,7 +60,6 @@ require ( github.com/prometheus/client_model v0.6.0 // indirect github.com/prometheus/procfs v0.12.0 // indirect github.com/r3labs/sse/v2 v2.10.0 // indirect - github.com/rs/cors v1.11.0 // indirect github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/tidwall/gjson v1.17.1 // indirect