Trying to fix similar issue, but have no idea why it's not working.
I have API: localhost:8080/api/acl/authorize
Have next http client:
const AUTH_URI = "/api/acl/"
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json',
'Access-Control-Allow-Origin': '*'
}
)
};
@Injectable({
providedIn: 'root'
})
export class AuthService {
constructor(private http: HttpClient) {
}
login(credentials: { login: string; passwordHash: string; }): Observable<any> {
return this.http.post(AUTH_URI + "authorize", {
login: credentials.login,
passwordHash: credentials.passwordHash
}, httpOptions);
}
}
Add proxy conf:
{
"/api/acl/authorize": {
"target": "http://localhost:8080/",
"secure": false,
"pathRewrite": {
"^/api/acl/authorize": ""
}
}
}
Starting with proxy option via ng serve --proxy-config proxy.config.json
(in packge.json).
Also tried "target": "http://localhost:8080/api/acl/authorize"
. But still have incorrect request POST http://localhost:4200/api/acl/authorize
instead of POST http://localhost:8080/api/acl/authorize
How can I fix this issue?
Aucun commentaire:
Enregistrer un commentaire