Moved BaseUrl from appsettings.json to Database and fixed an issue in UI for setting base url based on a hack, rather than asking backend for it. (#644)
This commit is contained in:
parent
e8e838d125
commit
977e364d5a
10 changed files with 52 additions and 26 deletions
10
UI/Web/src/app/_models/config-data.ts
Normal file
10
UI/Web/src/app/_models/config-data.ts
Normal file
|
@ -0,0 +1,10 @@
|
|||
/**
|
||||
* This is for base url only. Not to be used my applicaiton, only loading and bootstrapping app
|
||||
*/
|
||||
export class ConfigData {
|
||||
baseUrl: string = '/';
|
||||
|
||||
constructor(baseUrl: string) {
|
||||
this.baseUrl = baseUrl;
|
||||
}
|
||||
}
|
|
@ -31,6 +31,8 @@ import { CardsModule } from './cards/cards.module';
|
|||
import { CollectionsModule } from './collections/collections.module';
|
||||
import { ReadingListModule } from './reading-list/reading-list.module';
|
||||
import { SAVER, getSaver } from './shared/_providers/saver.provider';
|
||||
import { ConfigData } from './_models/config-data';
|
||||
|
||||
|
||||
@NgModule({
|
||||
declarations: [
|
||||
|
@ -83,7 +85,7 @@ import { SAVER, getSaver } from './shared/_providers/saver.provider';
|
|||
{provide: HTTP_INTERCEPTORS, useClass: JwtInterceptor, multi: true},
|
||||
Title,
|
||||
{provide: SAVER, useFactory: getSaver},
|
||||
{ provide: APP_BASE_HREF, useValue: window['_app_base' as keyof Window] || '/' },
|
||||
{ provide: APP_BASE_HREF, useFactory: (config: ConfigData) => config.baseUrl, deps: [ConfigData] },
|
||||
],
|
||||
entryComponents: [],
|
||||
bootstrap: [AppComponent]
|
||||
|
|
|
@ -40,9 +40,4 @@
|
|||
<app-root></app-root>
|
||||
<noscript>Please enable JavaScript to continue using this application.</noscript>
|
||||
</body>
|
||||
<script>
|
||||
(function() {
|
||||
window['_app_base'] = '/' + window.location.pathname.split('/')[1];
|
||||
})();
|
||||
</script>
|
||||
</html>
|
||||
|
|
|
@ -2,13 +2,21 @@ import { enableProdMode } from '@angular/core';
|
|||
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
||||
|
||||
import { AppModule } from './app/app.module';
|
||||
import { ConfigData } from './app/_models/config-data';
|
||||
import { environment } from './environments/environment';
|
||||
|
||||
|
||||
|
||||
if (environment.production) {
|
||||
enableProdMode();
|
||||
}
|
||||
|
||||
platformBrowserDynamic().bootstrapModule(AppModule)
|
||||
.catch(err => console.error(err));
|
||||
function fetchConfig(): Promise<ConfigData> {
|
||||
return fetch(environment.apiUrl + 'settings/base-url')
|
||||
.then(response => response.text())
|
||||
.then(response => new ConfigData(response));
|
||||
}
|
||||
|
||||
fetchConfig().then(config => {
|
||||
platformBrowserDynamic([ { provide: ConfigData, useValue: config } ])
|
||||
.bootstrapModule(AppModule)
|
||||
.catch(err => console.error(err));
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue