Skip to content

Commit

Permalink
Merge pull request #733 from oasisprotocol/andrew7234/always-use-cors
Browse files Browse the repository at this point in the history
always enable cors middleware, even on failing requests
  • Loading branch information
Andrew7234 authored Aug 2, 2024
2 parents 13805ba + d6abf3d commit 78bbdbb
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions .changelog/733.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
api: always enable cors
4 changes: 3 additions & 1 deletion cmd/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ func (s *Service) Start() {
BaseURL: v1BaseURL,
Middlewares: []apiTypes.MiddlewareFunc{
api.RuntimeFromURLMiddleware(v1BaseURL),
api.CorsMiddleware,
},
BaseRouter: baseRouter,
ErrorHandlerFunc: api.HumanReadableJsonErrorHandler,
})
// Manually apply the CORS middleware; we want it to run always.
// HandlerWithOptions() above does not apply it to some requests (404 URLs, requests with bad params, etc.).
handler = api.CorsMiddleware(handler)
// Manually apply the metrics middleware; we want it to run always, and at the outermost layer.
// HandlerWithOptions() above does not apply it to some requests (404 URLs, requests with bad params, etc.).
handler = api.MetricsMiddleware(metrics.NewDefaultRequestMetrics(moduleName), *s.logger)(handler)
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/damask/expected/bad_account.headers
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/damask/expected/bad_node.headers
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/damask/expected/spec.headers
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Accept-Ranges: bytes
Content-Length: UNINTERESTING
Content-Type: application/x-yaml
Last-Modified: UNINTERESTING
Vary: Origin
Date: UNINTERESTING

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/eden/expected/bad_account.headers
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/eden/expected/bad_node.headers
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down
1 change: 1 addition & 0 deletions tests/e2e_regression/eden/expected/spec.headers
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Accept-Ranges: bytes
Content-Length: UNINTERESTING
Content-Type: application/x-yaml
Last-Modified: UNINTERESTING
Vary: Origin
Date: UNINTERESTING

1 change: 1 addition & 0 deletions tests/e2e_regression/eden/expected/trailing_slash.headers
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Vary: Origin
X-Content-Type-Options: nosniff
Date: UNINTERESTING
Content-Length: UNINTERESTING
Expand Down

0 comments on commit 78bbdbb

Please sign in to comment.