-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: table for mapping routes between ICM and PWA
- Loading branch information
Showing
13 changed files
with
197 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { EffectsModule } from '@ngrx/effects'; | ||
|
||
import { HybridEffects } from './hybrid.effects'; | ||
|
||
@NgModule({ | ||
imports: [EffectsModule.forFeature([HybridEffects])], | ||
}) | ||
export class HybridStoreModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { isPlatformBrowser, isPlatformServer } from '@angular/common'; | ||
import { Inject, Optional, PLATFORM_ID } from '@angular/core'; | ||
import { TransferState, makeStateKey } from '@angular/platform-browser'; | ||
import { NavigationStart, Router } from '@angular/router'; | ||
import { Actions, Effect } from '@ngrx/effects'; | ||
import { Store, select } from '@ngrx/store'; | ||
import { filter, map, take, tap, withLatestFrom } from 'rxjs/operators'; | ||
|
||
import { getICMWebURL } from 'ish-core/store/configuration'; | ||
|
||
import { HYBRID_MAPPING_TABLE } from '../../../../hybrid/default-url-mapping-table'; | ||
|
||
const SSR_HYBRID_STATE = makeStateKey<boolean>('ssrHybrid'); | ||
|
||
export class HybridEffects { | ||
constructor( | ||
private actions: Actions, | ||
private router: Router, | ||
private store$: Store<{}>, | ||
@Inject(PLATFORM_ID) private platformId: string, | ||
private transferState: TransferState, | ||
@Optional() @Inject('SSR_HYBRID') private ssrHybridState: boolean | ||
) {} | ||
|
||
@Effect({ dispatch: false }) | ||
propagateSSRHybridPropToTransferState$ = this.actions.pipe( | ||
take(1), | ||
filter(() => isPlatformServer(this.platformId)), | ||
filter(() => !!this.ssrHybridState), | ||
tap(() => this.transferState.set(SSR_HYBRID_STATE, true)) | ||
); | ||
|
||
@Effect({ dispatch: false }) | ||
hybridApproachRedirectToICM$ = this.router.events.pipe( | ||
filter(() => isPlatformBrowser(this.platformId)), | ||
filter(() => this.transferState.get(SSR_HYBRID_STATE, false)), | ||
filter(event => event instanceof NavigationStart), | ||
map((event: NavigationStart) => event.url), | ||
withLatestFrom(this.store$.pipe(select(getICMWebURL))), | ||
tap(([url, icmWebUrl]) => { | ||
for (const entry of HYBRID_MAPPING_TABLE) { | ||
if (entry.handledBy === 'pwa') { | ||
continue; | ||
} | ||
const regex = new RegExp(entry.pwa); | ||
if (regex.exec(url)) { | ||
this.router.dispose(); | ||
const newUrl = url.replace(regex, `${icmWebUrl}/${entry.icmBuild}`); | ||
location.assign(newUrl); | ||
break; | ||
} | ||
} | ||
}) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { environment } from '../environments/environment'; | ||
|
||
const ICM_CONFIG_MATCH = `^/${environment.icmServerWeb}/(?<channel>[\\w-]+)/(?<lang>\\w+)/(?<application>[\\w-]+)/\\w+`; | ||
const PWA_CONFIG_BUILD = ';channel=$<channel>;lang=$<lang>;application=$<application>;redirect=1'; | ||
|
||
export interface HybridMappingEntry { | ||
/** ID for grouping */ | ||
id: string; | ||
/** regex for detecting ICM URL */ | ||
icm: string; | ||
/** regex for building ICM URL (w/o web url) */ | ||
icmBuild: string; | ||
/** regex for detecting PWA URL */ | ||
pwa: string; | ||
/** regex for building PWA URL */ | ||
pwaBuild: string; | ||
/** handler */ | ||
handledBy: 'icm' | 'pwa'; | ||
} | ||
|
||
/** | ||
* Mapping table for running PWA and ICM in parallel | ||
*/ | ||
export const HYBRID_MAPPING_TABLE: HybridMappingEntry[] = [ | ||
{ | ||
id: 'Home', | ||
icm: `${ICM_CONFIG_MATCH}/(Default|ViewHomepage)-Start.*$`, | ||
icmBuild: `ViewHomepage-Start`, | ||
pwa: `^/home.*$`, | ||
pwaBuild: `home${PWA_CONFIG_BUILD}`, | ||
handledBy: 'pwa', | ||
}, | ||
{ | ||
id: 'PDP', | ||
icm: `${ICM_CONFIG_MATCH}/ViewProduct-Start.*(\\?|&)SKU=(?<sku>[\\w-]+).*$`, | ||
icmBuild: `ViewProduct-Start?SKU=$<sku>`, | ||
pwa: `^.*/product/(?<sku>[\\w-]+).*$`, | ||
pwaBuild: `product/$<sku>${PWA_CONFIG_BUILD}`, | ||
handledBy: 'icm', | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters