question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cannot Render the content by using Angular7 SSR

See original GitHub issue

After using Angular7 SSR , I click the browser and View the page source . Cannot show the value get from the contentful .

Expected Behavior

Click the view page source at the browser. It should show all the value that receive from contentful

Actual Behavior

All the value from contentful at the page source is empty

Possible Solution

Steps to Reproduce

Context

Environment

Angular 7 . Angular universal

  • Language Version: V10.4.1
  • Package Manager Version: 6.4.1
  • Browser Version: Version 70.0.3538.102 (Official Build) (64-bit)
  • Operating System: Mac OS 10.14
  • Package Version: v7.0.5
  • Which API are you using?: Delivery

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
patrickhousleycommented, Dec 7, 2018

Maintainers, can you please expose the Axios adapter config option? This will allow Angular developers to write a custom adapter for Axios based on Angular’s HttpClient. This will allow us to use SSR with contentful in the Angular platform. At some point, a nice developer might even publish an axios angular adapter 😃.

Example using just plain Axios that worked is below. Should be fine for contentful.

@Injectable({
  providedIn: 'root',
})
export class HomeContentAdapterService {
  constructor(private readonly httpClient: HttpClient) {}

  getAdapter(): AxiosAdapter {
    return (config: AxiosRequestConfig): Promise<any> => {
      const { auth, headers, data, params } = config;

      if (auth) {
        const username = auth.username || '';
        const password = auth.password || '';
        headers.Authorization = 'Basic ' + btoa(username + ':' + password);
      }

      const request = this.httpClient.request(
        config.method.toUpperCase(),
        config.url,
        {
          body: data,
          headers,
          params,
          withCredentials: !!auth,
          reportProgress: true,
          observe: 'response'
        }
      );

      return request.toPromise().then((response: HttpResponse<any>) => {
        return {
          data: response.body,
          // IE sends 1223 instead of 204 (https://github.com/axios/axios/issues/201)
          status: response.status,
          statusText: response.statusText,
          headers: response.headers,
          config: config,
          request
        };
      });
    };
  }
}

@Injectable({
  providedIn: 'root',
})
export class HomeContentResolverService implements Resolve<any> {
  constructor(private readonly adapter: HomeContentAdapterService) {}

  async resolve() {
    const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1', {
      adapter: this.adapter.getAdapter()
    });

    return response.data;
  }
}
0reactions
marcolinkcommented, Mar 14, 2022

@r3plica You should be able to define your custom (angular) axios adapter when creating the contentful client. (see here)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Server side rendering not working in Angular 7
You can try using a snapshot build of @angular-devkit/build-angular ... then rebuild your project npm run build:ssr.
Read more >
Server-side rendering (SSR) with Angular Universal
This guide describes Angular Universal, a technology that renders Angular applications on the server. A normal Angular application executes in the browser, ...
Read more >
Server-side Rendering (SSR) with Angular Universal
Any new views required in the application can be created by using JavaScript solely on the client. Besides this, the request-response cycle still...
Read more >
Angular Server-side rendering (SSR) with Angular Universal
A typical Angular application executes in the browser, rendering pages in the DOM in response to user actions. Angular Universal executes on the...
Read more >
Pre-rendering Angular Applications - Blog - Brecht Billiet
SSR executes the Angular application on the server. That way the server will actually serve the compiled content in a way that search...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found