Home > Back-end >  can we use reserve word in rest api hosted in azure server
can we use reserve word in rest api hosted in azure server

Time:04-13

I have an application hosted in Azure server

I have a rest api for eg: http://localhost:8080/abc/bin , this api gives response in localhost.

BUT when I use http://mydevsite.com/abc/bin returns 404 , showing as cors error in browser console as below:

Access to XMLHttpRequest at 'http://mydevsite.com/abc/bin' from origin 'http://mysitee.com/abc/bin' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

and getting API response as below:

The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

I was told that "bin" word cannot be used at all in the rest api, bcoz firewall blocks having reserve word "bin" in the api (hosted in Azure server).

So, am looking for workaround for above "bin" word in the api.

Any solution really exists? orelse there is no way to use word "bin" in the rest api, especially when the code hosted in Azure server.

CodePudding user response:

Access to XMLHttpRequest at 'http://mydevsite.com/abc/bin' from origin 'http://mysitee.com/abc/bin' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
  • When the access-control-allow-origin header is missing in responses from domains other than your root page source, you'll get a missing CORS error.
  • In web.config ,you need to add few headers.If you dont have a web.config, create and add the below snippet
 <system.webServer>
    <httpProtocol>
      <customHeaders>
        <add  name="Access-Control-Allow-Origin"  value="*"  />       
        <add name="Access-Control-Allow-Methods" value="*" />
        <add name="Access-Control-Allow-Headers" value="*" />
      </customHeaders>
    </httpProtocol>
  </system.webServer>
  • If you want to enable cors policy only for the specified resource , replace * with the required links.
  • You can also Enable CORS from on the Azure Portal or by running below command in CLI
az webapp cors add --resource-group myResourceGroup --name <app-name> --allowed-origins '*'`

Please refer SO Thread for more information

  • Related