Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor WASM : http calls to FaunaDb blocked by CORS policy #109

Open
Toine-db opened this issue Jun 24, 2020 · 1 comment
Open

Blazor WASM : http calls to FaunaDb blocked by CORS policy #109

Toine-db opened this issue Jun 24, 2020 · 1 comment

Comments

@Toine-db
Copy link

Toine-db commented Jun 24, 2020

This library isn't working on Blazor WASM because of this 'x-query-timeout' header usage.

All HTTPClient calls get exceptions like:
Access to fetch at 'https://db.fauna.com/' from origin 'https://.....' has been blocked by CORS policy: Request header field x-query-timeout is not allowed by Access-Control-Allow-Headers in preflight response.

Until this issue is solved on the FaunaDB cloud side you can use the following workaround:
Remove the 'x-query-timeout' header in the request.

		public class MessageHandler : DelegatingHandler
		{
			public MessageHandler(HttpClientHandler httpClientHandler) :
				base(httpClientHandler) 
			{  }

			protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
			{
				// Dont use header 'X-Query-Timeout' for CORS policy
				request.Headers.Remove("X-Query-Timeout");
				return base.SendAsync(request, cancellationToken);
			}
		}
		public async void ContactFaunaDb()
		{
			var httpClient = new HttpClient(new MessageHandler(new HttpClientHandler()));
			var faunaDb = new FaunaClient(endpoint: Endpoint, secret: Secret, httpClient: httpClient);

			var rawIndexValues = await faunaDb.Query(Paginate(Match(Index("some_index"))));
			/// etc....
		}
@evbruno
Copy link
Contributor

evbruno commented Jun 24, 2020

Thanks for bringing this up. We are going to tackle this really soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants