From 6750247f6602da8f8cd2da6ec28be30849d51685 Mon Sep 17 00:00:00 2001 From: Solomon Laing Date: Tue, 20 Apr 2021 19:30:30 +0930 Subject: [PATCH] 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. --- src/app/projects/projects.service.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/app/projects/projects.service.ts b/src/app/projects/projects.service.ts index 384962d..a0e5e72 100644 --- a/src/app/projects/projects.service.ts +++ b/src/app/projects/projects.service.ts @@ -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. */ - private PROJECT_API_URL = "https://cms.inkletblot.com/" + private PROJECT_API_URL = "https://cms.inkletblot.com/api/json" constructor(private http: HttpClient) { } httpOptions = { headers: new HttpHeaders({ - 'Content-Type': 'application/json' + 'Content-Type': 'text/plain' }) }; @@ -48,7 +48,16 @@ export class ProjectsService { .subscribe( (response: Project[]) => { 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 } },