I have proxy.conf.json
{
"/api/*": {
"target": "https://api.dev.xyz.com",
"secure": false,
"changeOrigin": true,
"pathRewrite": { "^/api": "" },
"logLevel": "debug"
}
}
and I have ng serve --proxy-config proxy.conf.json in package.json file. When I run my project with npm start it showing error
ng serve --proxy-config proxy.conf.json
Browserslist: caniuse-lite is outdated. Please run next command `npm update`
10% building 3/3 modules 0 active[HPM] Proxy created: /api -> https://api.dev.xyz.com
[HPM] Proxy rewrite rule created: "^/api" ~> ""
[HPM] Subscribed to http-proxy events: [ 'error', 'close' ]
I have checked multiple stack-overflow answers reference link, but still I have been stuck here from long time.
http.get<any>('/api/something')it will replace/api/somethingwithhttps://api.dev.xyz.com/something.https://api.dev.xyz.com/api/loginwhen I try to hit still it is showingblocked by cors error in the browser console.this.http.get('https://api.dev.xyz.com/api/login')orthis.http.get('/api/login')(or eventhis.http.get('/api/api/login'), given the path rewrite in your proxy file)?this.http.get('https://api.dev.xyz.com/api/login')