2

I'm working with Angular 7.0.7 Angular Universal project. All seems to be working great, except for the SEO part. I followed a lot of tutorials, such as https://blog.worldline.tech/2018/03/08/angular-universal.html

The node server is supposed to do the GET part to display the page with the information already, but when I use https://search.google.com/structured-data/testing-tool none of that GET request is show.

import { HttpClient } from "@angular/common/http";
import { Component, OnInit, Inject } from "@angular/core";
import { Title, TransferState, makeStateKey } from "@angular/platform-browser";

export class TestComponent implements OnInit {
  test;

  constructor(
    @Inject(PLATFORM_ID) private _platformId: Object,
    private titleService: Title,
    private transferState: TransferState,
    private http: HttpClient
  ) {}

  ngOnInit() {
    this.test = [];

    let myTransferStateKey = makeStateKey<any>("myDatas");

    if (this.transferState.hasKey(myTransferStateKey)) {
      this.test = this.transferState.get(myTransferStateKey, {});
      this.transferState.remove(myTransferStateKey);

      console.log("Test w/o GET");
      console.log(this.test);
      console.log("transferstate key");
      console.log(myTransferStateKey);
    } else {
      this.http
        .get("https://reqres.in/api/users?page=2")
        .subscribe(response => {
          this.test = response["data"];
          this.transferState.set(myTransferStateKey, this.test);

          console.log("Test with GET");
          console.log(this.test);
          console.log("transferstate key");
          console.log(myTransferStateKey);
        });
    }
  }
}
<div class="container">
  <div class="row">
    <div class="col" *ngFor="let item of test">
      {{item.email}}
    </div>
  </div>
</div>

I expected the https://search.google.com/structured-data/testing-tool to show the list of users but it doesn't and instead it shows a <!---->.

I also tried doing a curl but is the same thing.

What I'm doing wrong? Thank you.

Evaldas Buinauskas
  • 13,739
  • 11
  • 55
  • 107
Jeannuel
  • 71
  • 5
  • 2
    I'm voting to close this question as off-topic because [it is about SEO, not programming](//meta.stackoverflow.com/a/382618). General SEO questions may be asked on [Webmasters.SE](//webmasters.stackexchange.com/). – Machavity Sep 04 '19 at 02:40
  • Thanks for the comment. I had an API that didnt work. That API was hosted in GoDaddy on a Shared Server, it worked to retrieve the data but for some reason I still I had this problem with Google. The fix for me was changing the API from a shared server to a VPS, I tried everything on the GoDaddy Shared Server side but didnt work, I changed to a Ubuntu VPS and it worked like the reqres and jsonplaceholder. – Jeannuel Sep 04 '19 at 14:19

0 Answers0