ultrasonicsoft / ng-cors-proxy

Angular application with CORS proxy configuration

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CORS Proxy solution

Summary

When you try to hit the web APIs but keep getting CORS error, you can try follow this approach.

  1. Create proxy.conf.json or proxy.conf.js file with proxy configuration
{
  "/api/*": {
    "target": "https://some-cloud-webapis.azurewebsites.net",
    "secure": false,
    "logLevel": "debug",
    "changeOrigin": true
  }
}
  1. In HttpClient methods, pass relative URLs
const url = '/api/services/app/GetSomething';
    return this.http.get<any>(url, httpOptions);
  1. Run application with proxy configuration
ng serve --proxy-config proxy.conf.json

You can also update angular.json file to include proxy configuration with ng serve command.

About

Angular application with CORS proxy configuration


Languages

Language:HTML 73.1%Language:TypeScript 22.3%Language:JavaScript 4.3%Language:CSS 0.2%