简体   繁体   中英

Where's the CORS setting gone in azure mobile services

TL/DR:

MSDN azure articles refer to going to the "Configure" section of the https://manage.windowsazure.com/ mobile services settings to add other URLS to CORS. It seems it isn't there anymore - any idea where it's gone?

The longer story for background:

Trying to follow this article: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-how-to-use-client-library/

and this linked one: http://azure.microsoft.com/en-us/documentation/articles/mobile-services-html-get-started-data/

I have followed the article and created an azure mobile service with a sql server database (and 1 simple table in it.)

I then try to connect to it on my web server ( localhost:8000/ ) with the js code:

var MobileServiceClient = WindowsAzure.MobileServiceClient;
var client = new MobileServiceClient('https://myappnamehere.azure-mobile.net/', 'mykeyhere');

I then make a call to query some data:

var table = client.getTable('mytablename');
var query = table.where({
    complete: false
}).read().done(function (results) {
    console.log(results);
}, function (err) {
    console.log(err);
});

And the where call runs the error callback with the message:

"XMLHttpRequest cannot load https://myappnamehere.azure-mobile.net/tables/tablename ?$filter=(complete%20eq%20false). No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'localhost:8000' is therefore not allowed access."

I'm guessing this is because although localhost is meant to be allowed in the server side CORS settings localhost:8000 isn't.

Trouble is, both articles above refer to going to the "Configure" section of the https://manage.windowsazure.com/ mobile services settings to add other URLS to CORS. It seems it isn't there anymore - any idea where it's gone?

All the other articles I look for talk about setting it in your config file etc. but the point is I don't want to push code to the server-side. That 1st article definitely implies that I can just create the service and the sql server table and then talk to it from javascript client-side (presumably automagically through the use of OData.) That is possible right or is that part of the article completely wrong too?!

If you're using the JavaScript (node.js) backend, then you'll see the list of cross-origin resource sharing (cors) domains. On the .NET backend, the support isn't baked in yet, but you should be able to add it by following the instructions to enable CORS for Web API (after all, the .NET backend is built on top of that platform).

Since you're accessing your service at localhost, I'm assuming that you're using the .NET backend, which is why you won't see the list of CORS domains in the portal. The integrated support should be coming in soon, but before that you can add the support manually as described in the document linked above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM