fix(restapi): Add cors headers when the request is returning errors #942
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, the REST endpoints don't return the CORS headers when they return an error.
One of the reasons is that Nim Presto has a weird behavior of adding the
Access-Control-Allow-Origin
header when a request is successful and omitting it when the request returns an error (see the method processRestRequest in nim-presto/presto/serverprivate.nim).This PR fixes this behavior by adding the CORS headers whenever a response is returned. I was hesitant to create an
OPTIONS
endpoint for every request, as we did for the data upload, but it does not work with simple requests because noOPTIONS
request is sent by the browser in that case.Without the CORS headers returned when an endpoint returns an error, I am unable to display the error message to the user. Moreover, I am not able to know if the Marketplace is enabled or not (see codex-storage/codex-marketplace-ui#29).