Skip to content

Commit b8e514b

Browse files
committed
fix: add minimal docs
1 parent 77bf7a9 commit b8e514b

File tree

4 files changed

+113
-122
lines changed

4 files changed

+113
-122
lines changed

README.md

+3-121
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
The project contains:
66

77
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
99
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
1212
2. One side publishable library:
1313
- `ngx-rickandmorty`
1414
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:
1818
All developed libraries are used in the application.
1919

2020
[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-
```

libs/ngx-ssr/cache/README.md

+45
Original file line numberDiff line numberDiff line change
@@ -1 +1,46 @@
11
# @ngx-ssr/cache
2+
3+
Install package
4+
5+
```bash
6+
npm i @ngx-ssr/cache
7+
```
8+
9+
Import the `NgxSsrCacheModule` module to cache all GET requests
10+
11+
```ts
12+
import { BrowserModule } from '@angular/platform-browser';
13+
import { NgModule } from '@angular/core';
14+
import { AppComponent } from './app.component';
15+
import { NgxSsrCacheModule } from '@ngx-ssr/cache';
16+
import { environment } from '../environments/environment';
17+
18+
@NgModule({
19+
declarations: [AppComponent],
20+
imports: [
21+
BrowserModule,
22+
NgxSsrCacheModule.configLruCache({ maxAge: 10 * 60_000, maxSize: 50 }),
23+
],
24+
bootstrap: [AppComponent],
25+
})
26+
export class AppModule {
27+
}
28+
```
29+
30+
HTML caching is also available for express
31+
32+
```ts
33+
import { ngExpressEngine } from '@nguniversal/express-engine';
34+
import { LRUCache } from '@ngx-ssr/cache';
35+
import { withCache } from '@ngx-ssr/cache/express';
36+
37+
server.engine(
38+
'html',
39+
withCache(
40+
new LRUCache({ maxAge: 10 * 60_000, maxSize: 100 }),
41+
ngExpressEngine({
42+
bootstrap: AppServerModule,
43+
})
44+
)
45+
);
46+
```

libs/ngx-ssr/platform/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -1 +1,37 @@
11
# @ngx-ssr/platform
2+
3+
Install package
4+
5+
```bash
6+
npm i @ngx-ssr/platform
7+
```
8+
9+
To determine the platform, use the tokens `IS_SERVER_PLATFORM` and `IS_BROWSER_PLATFORM`
10+
11+
```ts
12+
@Directive({
13+
selector: '[some-directive]',
14+
})
15+
export class SomeDirective {
16+
constructor(
17+
@Inject(IS_SERVER_PLATFORM) isServer: boolean,
18+
) {
19+
if (isServer) {
20+
viewContainer.createEmbeddedView(templateRef);
21+
}
22+
}
23+
}
24+
```
25+
26+
Use the `ifIsServer` and ` ifIsBrowser` structural directives in your template for rendering contents depending on the
27+
platform:
28+
29+
```ts
30+
@Component({
31+
selector: 'ram-root',
32+
template: '<some-сomp *ifIsServer"></some-сomp>',
33+
styleUrls: ['./app.component.less'],
34+
})
35+
export class AppComponent {
36+
}
37+
```

libs/ngx-ssr/timeout/README.md

+29-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
# @ngx-ssr/timeout
1+
2+
Install package
3+
4+
```bash
5+
npm i @ngx-ssr/timeout
6+
```
7+
8+
Use `NgxSsrTimeoutModule` to set timeouts for all requests
9+
10+
```ts
11+
import { NgModule } from '@angular/core';
12+
import {
13+
ServerModule,
14+
} from '@angular/platform-server';
15+
import { AppModule } from './app.module';
16+
import { AppComponent } from './app.component';
17+
import { NgxSsrTimeoutModule } from '@ngx-ssr/timeout';
18+
19+
@NgModule({
20+
imports: [
21+
AppModule,
22+
ServerModule,
23+
NgxSsrTimeoutModule.forRoot({ timeout: 500 }),
24+
],
25+
bootstrap: [AppComponent],
26+
})
27+
export class AppServerModule {
28+
}
29+
```

0 commit comments

Comments
 (0)