Skip to content

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

@Toine-db

Description

@Toine-db

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....
		}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions