Hi I am working in c# azure function and java-script. I have web page running locally and hitting azure function also in locally. Below is my azure function and it runs in
negotiate: [POST] http://localhost:7071/api/negotiate
[FunctionName("negotiate")]
public static async Task<SignalRConnectionInfo> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequest req, IBinder binder,
ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
var data = await Authenticated(req, log);
var connectionInfo = binder.Bind<SignalRConnectionInfo>(new SignalRConnectionInfoAttribute { HubName = "MapUpload", UserId = data });
return connectionInfo;
}
Then in local.settings.json I have configured
"Host": {
"CORS": "*"
}
Below is my java-script code.
<script>
const connection = new signalR.HubConnectionBuilder()
.withUrl('http://localhost:7071/api/')
.configureLogging(signalR.LogLevel.Information)
.build();
connection.on('MapUpload', productOrdered);
connection.onclose(() => console.log('disconnected'));
console.log('connecting...');
connection.start()
.then(() => data.ready = true)
.catch(console.error);
</script>
When I run run my javascript application I get below error
Access to XMLHttpRequest at 'http://localhost:7071/api/negotiate' from origin 'http://localhost:3872' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
I have added "CORS": "*" but still gives me above error. So May I know Is there configurations I am missing in the above code. Can someone help em to understand this issue? Any help would be greatly appreciated. Thank you