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

Angular Universal + Https - Home page view-source

Patryk Panek
1#
Patryk Panek Published in 2018-02-13 09:47:29Z

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 ?

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO