Angular Integration with Delphi

Asked

Viewed 146 times

-1

I have a Delphi Datasnap Restful server to be accessed with Angular front-end, I was able to apply GET normally but in trying to run a DELETE I get the http error Failure Would anyone know how to solve this problem?

Access to XMLHttpRequest at 'http://192.168.1.2:1738/datasnap/rest/tservico/natureza:1...' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.

1 answer

1

By default browsers do not accept that your site receives data from another source other than the same origin, CORS means (Resources from cross origins), for security reasons is disabled.

So what you can do is release on the server the CORS Header for your domain or * for all domains. Another solution is to have Angular tell the browser that the address of your request is the same origin, you can do this by creating a Proxy .conf.json in the app src:

{
  "/api": {
    "target": "http://192.168.1.2:1738",
    "secure": false,
    "changeOrigin": true
  }
}

And in the start command you must add the proxy to the flag --proxy-config:

"start": "./node_modules/.bin/ng serve  --proxy-config ./proxy.conf.json"

Or configure in ng serve angular.json

"serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "NOMEDOSEUAPP:build",
        "proxyConfig": "src/proxy.conf.json"
      }

Obs: in your request urls you will use only /api/path

Browser other questions tagged

You are not signed in. Login or sign up in order to post.