Hello!
I'm creating a just a simple CRUD Angular & Codeigniter for the Backend,
Everything is working with my API ( Tried with Postman )
But when i want to post my request, i have a CORS ERROR
Access to XMLHttpRequest at 'http://localhost:8081/api/task' 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.
I had the same before, when i was getting the DATA,
so i did a proxy conf
{
"/api/**": {
"target": "http://localhost:8081",
"secure": false,
"logLevel": "debug",
"changeOrigin": true
}
}
angular.json
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "X:build:production",
"proxyConfig": "src/proxy.conf.json"
},
"development": {
"browserTarget": "X:build:development",
"proxyConfig": "src/proxy.conf.json"
}
},
"defaultConfiguration": "development"
},
service
addTask(task: Task) {
return this.http.post<Task>('http://localhost:8081/api/task', task);
}
component
onAddTask(form: NgForm) {
const value = form.value;
const newTask = new Task(value.name, value.description);
this.taskService.addTask(newTask).subscribe((task: Task) => {
console.log(task);
});
form.reset();
}