5
5
The project contains:
6
6
7
7
1 . Three publishable libraries:
8
- - ` @ngx-ssr/cache ` - in-memory implementation of the cache for GET requests and HTML. It is possible to change the
8
+ - [ @ngx-ssr/cache ] ( ./libs/ngx-ssr/cache/README.md ) - in-memory implementation of the cache for GET requests and HTML. It is possible to change the
9
9
storage.
10
- - ` @ngx-ssr/timeout ` — implementation of timeout for requests
11
- - ` @ngx-ssr/platform ` — utilities for convenient work with platform-specific data
10
+ - [ @ngx-ssr/timeout ] ( ./libs/ngx-ssr/timeout/README.md ) — implementation of timeout for requests
11
+ - [ @ngx-ssr/platform ] ( ./libs/ngx-ssr/platform/README.md ) — utilities for convenient work with platform-specific data
12
12
2 . One side publishable library:
13
13
- ` ngx-rickandmorty `
14
14
3 . [ The Rick and Morty application] ( https://ng-rickandmorty.web.app/character ) based on the Rick and Morty API. The
@@ -18,121 +18,3 @@ The project contains:
18
18
All developed libraries are used in the application.
19
19
20
20
[ Taiga UI] ( https://taiga-ui.dev/ ) is used as a UI framework.
21
-
22
- # How to use
23
-
24
- ## @ngx-ssr/cache
25
-
26
- Install package
27
-
28
- ``` bash
29
- npm i @ngx-ssr/cache
30
- ```
31
-
32
- Import the ` NgxSsrCacheModule ` module to cache all GET requests
33
-
34
- ``` ts
35
- import { BrowserModule } from ' @angular/platform-browser' ;
36
- import { NgModule } from ' @angular/core' ;
37
- import { AppComponent } from ' ./app.component' ;
38
- import { NgxSsrCacheModule } from ' @ngx-ssr/cache' ;
39
- import { environment } from ' ../environments/environment' ;
40
-
41
- @NgModule ({
42
- declarations: [AppComponent ],
43
- imports: [
44
- BrowserModule ,
45
- NgxSsrCacheModule .configLruCache ({ maxAge: 10 * 60_000 , maxSize: 50 }),
46
- ],
47
- bootstrap: [AppComponent ],
48
- })
49
- export class AppModule {
50
- }
51
- ```
52
-
53
- HTML caching is also available for express
54
-
55
- ``` ts
56
- import { ngExpressEngine } from ' @nguniversal/express-engine' ;
57
- import { LRUCache } from ' @ngx-ssr/cache' ;
58
- import { withCache } from ' @ngx-ssr/cache/express' ;
59
-
60
- server .engine (
61
- ' html' ,
62
- withCache (
63
- new LRUCache ({ maxAge: 10 * 60_000 , maxSize: 100 }),
64
- ngExpressEngine ({
65
- bootstrap: AppServerModule ,
66
- })
67
- )
68
- );
69
- ```
70
-
71
- ## @ngx-ssr/timeout
72
-
73
- Install package
74
-
75
- ``` bash
76
- npm i @ngx-ssr/timeout
77
- ```
78
-
79
- Use ` NgxSsrTimeoutModule ` to set timeouts for all requests
80
-
81
- ``` ts
82
- import { NgModule } from ' @angular/core' ;
83
- import {
84
- ServerModule ,
85
- } from ' @angular/platform-server' ;
86
- import { AppModule } from ' ./app.module' ;
87
- import { AppComponent } from ' ./app.component' ;
88
- import { NgxSsrTimeoutModule } from ' @ngx-ssr/timeout' ;
89
-
90
- @NgModule ({
91
- imports: [
92
- AppModule ,
93
- ServerModule ,
94
- NgxSsrTimeoutModule .forRoot ({ timeout: 500 }),
95
- ],
96
- bootstrap: [AppComponent ],
97
- })
98
- export class AppServerModule {
99
- }
100
- ```
101
-
102
- ## @ngx-ssr/platform
103
-
104
- Install package
105
-
106
- ``` bash
107
- npm i @ngx-ssr/platform
108
- ```
109
-
110
- To determine the platform, use the tokens ` IS_SERVER_PLATFORM ` and ` IS_BROWSER_PLATFORM `
111
-
112
- ``` ts
113
- @Directive ({
114
- selector: ' [some-directive]' ,
115
- })
116
- export class SomeDirective {
117
- constructor (
118
- @Inject (IS_SERVER_PLATFORM ) isServer : boolean ,
119
- ) {
120
- if (isServer ) {
121
- viewContainer .createEmbeddedView (templateRef );
122
- }
123
- }
124
- }
125
- ```
126
-
127
- Use the ` ifIsServer ` and ` ifIsBrowser ` structural directives in your template for rendering contents depending on the
128
- platform:
129
-
130
- ``` ts
131
- @Component ({
132
- selector: ' ram-root' ,
133
- template: ' <some-сomp *ifIsServer"></some-сomp>' ,
134
- styleUrls: [' ./app.component.less' ],
135
- })
136
- export class AppComponent {
137
- }
138
- ```
0 commit comments