I'm trying to submit data from my Angular 9 App to a bottle backend server. On the clientside I'm getting the CORS Errror, that a 'Access-Control-Allow-Origin' header is missing. Also it says that the same-origin rule is blocking the request. On the backend it just prints the status code 405. When I perform the request via Postman however, everything is working fine. What changes do I have to do in order to make it work? I want it also to be working in production mode. Here's my code: Angular component.ts:
onSubmit(form) {
console.log(form.value);
this.http.post('http://localhost:8080/contact', form.value).subscribe();
}
My bottle backend server:
@post('/contact')
def progress_contact():
response.set_header('Content-Type', 'application/json')
response.set_header('Access-Control-Allow-Origin', 'http://localhost:4200')
response.set_header('Access-Control-Allow-Methods', 'PUT, GET, POST, OPTIONS, DELETE')
response.set_header('Access-Control-Allow-Headers', 'Access-Control-Allow-Origin, Content-Type, Accept, Accept-Language, Origin, User-Agent')
print(request)
print(request.POST.moin)
print(request.POST.email)
return 'hello'
As I mentioned, when performing a POST-Request via Postman, I get 'hello' in the response object and also the server prints the values I sent.