How to execute http-requests with angular universal prerender?

Viewed 175

I just added an angular universal prerender to my app by running ng add @nguniversal/express-engine by following this tutorial

In my application I am making two simple http calls on app.component so it runs when application starts.

  private getDataOne(name) {
    return this.http.get('http://localhost:3000/api/one');
  }

  private getDataTwo(name) {
    return this.http.get('http://localhost:3000/api/two');
  }

However when I prerender my application with this command npm run prerender it seems it still calling the server. So I wonder how would you execute http so when you server prerendered app it would use existing value and no execute http?

I've tried to put my endpoint to server.ts but it is didn't help

server.get('http://localhost:3000/api/**', (req, res) => {});

also I tried that but no luck

  server.get('http://localhost:3000/api/one', (req, res) => res.json());
  server.get('http://localhost:3000/api/two', (req, res) => res.json());
0 Answers
Related