Home Angular Universal + Https - Home page view-source
Reply: 0

Angular Universal + Https - Home page view-source

user48226
1#
user48226 Published in September 20, 2018, 4:36 pm

I have strange problem with Angular 5 + Angular Universal + Https protocal. I can check view-source in browser on every page except home page with /:lang route. I did AuthGuard for home page like that :

import { Injectable }     from '@angular/core';
import { CanActivate }    from '@angular/router';
import { Router } from '@angular/router';
import { Config } from '../config';



@Injectable()
export class AuthGuard implements CanActivate {
langUrl : string;

  constructor(private router: Router, private config: Config) {
      this.langUrl = this.config.getLanguage();
  }
  canActivate() {
    this.router.navigate(['/' + this.langUrl]);
    return true;
  }
}

It's working well for every platform server/browser. In config my function getLanguage() looks like :

  isSessionAvaible() {
    var test = 'test';
    try {
      localStorage.setItem(test, test);
      localStorage.removeItem(test);
      return true;
    } catch (e) {
      return false;
    }
  }

  getLanguage() {
    if (this.isSessionAvaible()) {
      return localStorage
        .getItem('lang.url');
    } else {
      return this.defaultLang;
    }

}

When I'm trying to enter https://example.org. Guard always redirect me to https://example.org/en and there I can't see view-source in browser. See screen below.

When I'm deleting Node.js Express Server https redirect, which looks like :

var forceSsl = function (req, res, next) {
  if (req.headers['x-forwarded-proto'] !== 'https') {
      return res.redirect(['https://', req.get('Host'), req.url].join(''));
  }
  return next();
};


app.use(forceSsl);

And then visit page without https http://example.orgAuthGuard redirect me to http://example.org/en and view-source in browser looks like :

After that when I'm trying to enter https://example.org/ without server https redirect, view-source is same like in first example (with https redirect).

Do you know how to repair it ? How to show view-source on https home page also ?

share|improve this question
  • So it works for ALL other pages, with https ? And what if you try to access example.org/en directly ? – David Feb 13 at 11:36
  • 1. https://example.org/ - don't work after redirect to https://example.org/en 2. http://example.org/ - don't work after redirect to https://example.org/en 3. http://example.org/ - work (without https redirect) after redirect to http://example.org/en 4. https://example.org/en 5. http://example.org/en - work (without redirect https redirect) – Patryk Panek Feb 13 at 11:51
  • yeah but what about https://example.com/en directly ? – David Feb 13 at 12:55
  • It works without any problems. – Patryk Panek Feb 13 at 12:56
  • Can you check the 'Location' header returned by the server when you access https://example.com? – David Feb 13 at 12:58

active oldest votes

Your Answer

StackExchange.ifUsing("editor", function () { StackExchange.using("externalEditor", function () { StackExchange.using("snippets", function () { StackExchange.snippets.init(); }); }); }, "code-snippets"); StackExchange.ready(function() { var channelOptions = { tags: "".split(" "), id: "1" }; initTagRenderer("".split(" "), "".split(" "), channelOptions); StackExchange.using("externalEditor", function() { // Have to fire editor after snippets, if snippets enabled if (StackExchange.settings.snippets.snippetsEnabled) { StackExchange.using("snippets", function() { createEditor(); }); } else { createEditor(); } }); function createEditor() { StackExchange.prepareEditor({ heartbeatType: 'answer', convertImagesToLinks: true, noModals: false, showLowRepImageUploadWarning: true, reputationToPostImages: 10, bindNavPrevention: true, postfix: "", onDemand: true, discardSelector: ".discard-answer" ,immediatelyShowMarkdownHelp:true }); } });
 
StackExchange.ready( function () { StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f48763770%2fangular-universal-https-home-page-view-source%23new-answer', 'question_page'); } );

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged angular redirect https angular-universal view-source or ask your own question.

StackExchange.ready(function(){$.get('/posts/48763770/ivc/af20');});
StackExchange.ready(function () { StackExchange.responsiveness.addSwitcher(); }) (function(i, s, o, g, r, a, m) { i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function() { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o), m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m); })(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga'); StackExchange.ready(function () { StackExchange.ga.init({ sendTitles: true, tracker: window.ga, trackingCodes: [ 'UA-108242619-1' ] }); StackExchange.ga.setDimension('dimension2', '|angular|redirect|https|angular-universal|view-source|'); StackExchange.ga.setDimension('dimension3', 'Questions/Show'); StackExchange.ga.trackPageView(); }); /**/ var _qevents = _qevents || [], _comscore = _comscore || []; (function() { var ssl = 'https:' == document.location.protocol, s = document.getElementsByTagName('script')[0], qc = document.createElement('script'); qc.async = true; qc.src = (ssl ? 'https://secure' : 'http://edge') + '.quantserve.com/quant.js'; s.parentNode.insertBefore(qc, s); _qevents.push({ qacct: "p-c1rF4kxgLUzNc" }); /**/ var sc = document.createElement('script'); sc.async = true; sc.src = (ssl ? 'https://sb' : 'http://b') + '.scorecardresearch.com/beacon.js'; s.parentNode.insertBefore(sc, s); _comscore.push({ c1: "2", c2: "17440561" }); })();
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.311697 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO