Fixed the reverse proxy

This commit is contained in:
tidusjar 2019-06-07 22:33:28 +01:00
parent f4903419d3
commit 11f91de16b
2 changed files with 43 additions and 44 deletions

View file

@ -83,9 +83,9 @@ const routes: Routes = [
// AoT requires an exported function for factories // AoT requires an exported function for factories
export function HttpLoaderFactory(http: HttpClient, platformLocation: PlatformLocation) { export function HttpLoaderFactory(http: HttpClient, platformLocation: PlatformLocation) {
// const base = getBaseLocation(); // const base = getBaseLocation();
const base = platformLocation.getBaseHrefFromDOM(); const base = '/' + (window.location.pathname.split('/')[1] || '')
const version = Math.floor(Math.random() * 999999999); const version = Math.floor(Math.random() * 999999999);
if (base.length > 1) { if (base !== null && base.length > 1) {
return new TranslateHttpLoader(http, `${base}/translations/`, `.json?v=${version}`); return new TranslateHttpLoader(http, `${base}/translations/`, `.json?v=${version}`);
} }
return new TranslateHttpLoader(http, "/translations/", `.json?v=${version}`); return new TranslateHttpLoader(http, "/translations/", `.json?v=${version}`);
@ -181,11 +181,10 @@ export function JwtTokenGetter() {
MessageService, MessageService,
StorageService, StorageService,
SignalRNotificationService, SignalRNotificationService,
{ provide: APP_BASE_HREF, useValue: window['_app_base'] || '/' } {
// { provide: APP_BASE_HREF,
// provide: APP_BASE_HREF, useValue: '/' + (window.location.pathname.split('/')[1] || '')
// useFactory: getBaseLocation }
// }
], ],
bootstrap: [AppComponent], bootstrap: [AppComponent],
}) })

View file

@ -5,43 +5,43 @@
<script> <script>
// manually sets the <base> tag's href attribute so the app can be located in places other than root // manually sets the <base> tag's href attribute so the app can be located in places other than root
var split = location.pathname.split('/'); // var split = location.pathname.split('/');
var base = ""; // var base = "";
var invalidProxies = ['DISCOVER', // var invalidProxies = ['DISCOVER',
'REQUESTS-LIST', // 'REQUESTS-LIST',
'DETAILS', // 'DETAILS',
'SETTINGS', // 'SETTINGS',
'ISSUES', // 'ISSUES',
'USERMANAGEMENT', // 'USERMANAGEMENT',
'RECENTLYADDED', // 'RECENTLYADDED',
'DETAILS', // 'DETAILS',
'VOTE', // 'VOTE',
'LOGIN', // 'LOGIN',
'LANDINGPAGE', // 'LANDINGPAGE',
'TOKEN', // 'TOKEN',
'RESET', // 'RESET',
'CUSTOM', // 'CUSTOM',
'AUTH', // 'AUTH',
'WIZARD', // 'WIZARD',
"CALENDAR" // "CALENDAR"
] // ]
for (var i = 0; i < split.length - 1; i++) { // for (var i = 0; i < split.length - 1; i++) {
if( invalidProxies.indexOf(split[i].toUpperCase()) !== -1) { // if( invalidProxies.indexOf(split[i].toUpperCase()) !== -1) {
break; // break;
} // }
base += split[i]; // base += split[i];
if(base.length > 1) { // if(base.length > 1) {
break; // break;
} // }
if (i < split.length - 2) { // if (i < split.length - 2) {
base += "/"; // base += "/";
} // }
} // }
if(base === "") { // if(base === "") {
base = "/"; // base = "/";
} // }
window['_app_base'] = base; // window['_app_base'] = base;
document.write("<base href='" + base + "' />"); // document.write("<base href='" + base + "' />");
</script> </script>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">