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.

SSR not working with HTTPS API URL

See original GitHub issue

Note: for support questions, please use one of these channels: https://github.com/angular/universal/blob/master/CONTRIBUTING.md#question. This repository’s issues are reserved for feature requests and bug reports. Also, Preboot has moved to https://github.com/angular/preboot - please make preboot-related issues there.

  • I’m submitting a …
- [ ] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
  • What modules are related to this Issue?
- [ ] aspnetcore-engine
- [ ] express-engine
- [ ] hapi-engine
  • Do you want to request a feature or report a bug?

  • What is the current behavior?

  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.

  • What is the expected behavior?

  • What is the motivation / use case for changing the behavior?

  • Please tell us about your environment:

  • Angular version: 4.1
  • Browser: [all ]
  • Language: [TypeScript 2.3.1]
  • OS: [all ]
  • Platform: [NodeJs | PHP]
  • Other information (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow, gitter, etc)

SSR fail when we using https api url for seo meta information. Using http working perfect.

Any solution please help me regards this.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:9
  • Comments:45 (3 by maintainers)

github_iconTop GitHub Comments

26reactions
tedisherocommented, Nov 6, 2018

It worked for me after I added this line to my server.ts file “process.env.NODE_TLS_REJECT_UNAUTHORIZED = ‘0’;”

5reactions
jaguar7021commented, Aug 18, 2019

Hi all. I found the problem for me. On my server I setup port forwarding by iptables iptables --table nat --append PREROUTING --protocol tcp --dport 443 --jump REDIRECT --to-ports 3000

That is, my web server is running on port 3000. I did not take this into account when copying the UniversalInterceptor code from the official documentation

Now I fixed it and SSR works correctly. My universal-interceptor.ts

import { Request } from 'express';
import { REQUEST } from '@nguniversal/express-engine/tokens';
import { Inject, Injectable, Optional } from '@angular/core';
import { HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';

@Injectable()
export class UniversalInterceptor implements HttpInterceptor {

    constructor(
        @Optional() @Inject(REQUEST) protected request: Request,
        @Optional() @Inject('REQUEST') protected origin_request: any
    ) {}

    intercept(req: HttpRequest<any>, next: HttpHandler) {
        let serverReq: HttpRequest<any> = req;

        if (this.request) {
            let host = this.request.get('host');
            /**
             * Fix production SSR error
             */
            if (!host.includes(':')) {
                host += ':3000';
            }

            let newUrl = `${this.request.protocol}://${host}`;
            if (!req.url.startsWith('/')) {
                newUrl += '/';
            }

            serverReq = req.clone({
                url: newUrl + req.url,
                setHeaders: {
                    cookie: this.origin_request ? this.origin_request.headers.cookie : ''
                }
            });
        }

        return next.handle(serverReq);
    }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot perform https request in ssr - node.js - Stack Overflow
I ran https.get('<my-api-url>') in a Node shell and I got: Uncaught Error: unable to verify the first certificate ...
Read more >
Server-Side Rendering - Vite
Server-Side Rendering # ... SSR specifically refers to front-end frameworks (for example React, Preact, Vue, and Svelte) that support running the same application ......
Read more >
Angular Universal: Complete Practical Guide
This post will be a complete practical guide for getting started with Angular Universal. We are going to go start with an existing...
Read more >
Blog - Next.js 13
Next.js 13 introduces layouts, React Server Components, and streaming in the app directory, as well as Turbopack, an improved image ...
Read more >
Usage with Next.js - tRPC
If you want to use SSR, you need to use the server's full URL. * @link https://trpc.io/docs/ssr. **/. url: `${getBaseUrl()}/api/trpc`,.
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