Got api request working.

I added the necessary header to the api server and then changed the content type of the request to text/plain to disabled the preflight OPTIONS request which the server was erroring on.
Not sure about the security of all this but it's a very basic website and I don't think it'll be an issue.
This commit is contained in:
Solomon Laing 2021-04-20 19:30:30 +09:30
parent 9a1d147073
commit 6750247f66

View File

@ -32,13 +32,13 @@ export class ProjectsService {
* I am actively avoiding any kind of environment management, this is a very basic site and currently this is the only api call. * I am actively avoiding any kind of environment management, this is a very basic site and currently this is the only api call.
*/ */
private PROJECT_API_URL = "https://cms.inkletblot.com/" private PROJECT_API_URL = "https://cms.inkletblot.com/api/json"
constructor(private http: HttpClient) { } constructor(private http: HttpClient) { }
httpOptions = { httpOptions = {
headers: new HttpHeaders({ headers: new HttpHeaders({
'Content-Type': 'application/json' 'Content-Type': 'text/plain'
}) })
}; };
@ -48,7 +48,16 @@ export class ProjectsService {
.subscribe( .subscribe(
(response: Project[]) => { (response: Project[]) => {
if (response) { if (response) {
this.allProjects = response; // using text/plain so as to not get the preflight options request
// as such : Project[] does not work as expected and objects must be parsed.
for (let project of response) {
this.allProjects.push({
title : project.title,
description : project.description,
ct : project.ct,
body : project.body
});
}
// filter out different categories here currently only one // filter out different categories here currently only one
} }
}, },