forked from nestjs/ng-universal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db6fb9c
commit 84c35cd
Showing
18 changed files
with
1,176 additions
and
7,549 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export const ANGULAR_UNIVERSAL_OPTIONS = 'ANGULAR_UNIVERSAL_OPTIONS'; | ||
|
||
export const ANGULAR_UNIVERSAL_CACHE_OPTIONS = | ||
'ANGULAR_UNIVERSAL_CACHE_OPTIONS'; |
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
17 changes: 17 additions & 0 deletions
17
lib/interfaces/angular-universal-cache-options.interface.ts
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,17 @@ | ||
import { CacheKeyGenerator } from './cache-key-generator.interface'; | ||
import { CacheStorage } from './cache-storage.interface'; | ||
|
||
interface CacheOptionsEnabled { | ||
isEnabled: true; | ||
storage: CacheStorage; | ||
expiresIn: number; | ||
keyGenerator: CacheKeyGenerator; | ||
} | ||
|
||
interface CacheOptionsDisabled { | ||
isEnabled: false; | ||
} | ||
|
||
export type AngularUniversalCacheOptions = | ||
| CacheOptionsEnabled | ||
| CacheOptionsDisabled; |
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,31 @@ | ||
import { CacheKeyByOriginalUrlGenerator } from '../cache/cache-key-by-original-url.generator'; | ||
import { InMemoryCacheStorage } from '../cache/in-memory-cache.storage'; | ||
import { AngularUniversalCacheOptions } from '../interfaces/angular-universal-cache-options.interface'; | ||
import { AngularUniversalOptions } from '../interfaces/angular-universal-options.interface'; | ||
|
||
const DEFAULT_CACHE_EXPIRATION_TIME = 60000; // 60 seconds | ||
|
||
export function angularUniversalCacheOptionsFactory( | ||
ngOptions: AngularUniversalOptions | ||
): AngularUniversalCacheOptions { | ||
if (!ngOptions.cache) { | ||
return { | ||
isEnabled: false | ||
}; | ||
} | ||
if (typeof ngOptions.cache !== 'object') { | ||
return { | ||
isEnabled: true, | ||
storage: new InMemoryCacheStorage(), | ||
expiresIn: DEFAULT_CACHE_EXPIRATION_TIME, | ||
keyGenerator: new CacheKeyByOriginalUrlGenerator() | ||
}; | ||
} | ||
return { | ||
isEnabled: true, | ||
storage: ngOptions.cache.storage ?? new InMemoryCacheStorage(), | ||
expiresIn: ngOptions.cache.expiresIn ?? DEFAULT_CACHE_EXPIRATION_TIME, | ||
keyGenerator: | ||
ngOptions.cache.keyGenerator ?? new CacheKeyByOriginalUrlGenerator() | ||
}; | ||
} |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
export { REQUEST, RESPONSE } from '@nguniversal/express-engine/tokens'; | ||
import { InjectionToken } from '@angular/core'; | ||
import { Request, Response } from 'express'; | ||
|
||
export const REQUEST = new InjectionToken<Request>('REQUEST'); | ||
export const RESPONSE = new InjectionToken<Response>('RESPONSE'); | ||
|
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
Oops, something went wrong.