Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b3df93b

Browse files
committed
chore: fix format
1 parent 9d02a1c commit b3df93b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+679
-482
lines changed

libs/isr-move/README.md

Lines changed: 70 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33
</p>
44

55
# Incremental Static Regeneration for Angular
6+
67
A library that enables Angular Universal applications to generate static pages at runtime and then update them incrementally on demand or on a schedule.
78

89
📰 [Documentation](https://ngx-isr.vercel.app/)
910

1011
📰 [ISR Blog post](https://itnext.io/incremental-static-regeneration-for-angular-42b0a8440e53)
1112

1213
# Features
14+
1315
- ⏰ Scheduled cache invalidation
1416
- ▶️ On-demand cache invalidation
15-
- 🔌 Plugin based cache handlers
17+
- 🔌 Plugin based cache handlers
1618
- 👌 No build changes required!
1719
- 🅰️ Supports Angular Universal
1820
- 🛡️ NgModules & Standalone Compatible
1921

2022
# How to use it?
2123

2224
1. Install npm package
25+
2326
```bash
2427
npm install ngx-isr
2528
# or
@@ -29,74 +32,88 @@ pnpm add ngx-isr
2932
```
3033

3134
2. Initialize `ISRHandler` inside `server.ts`
35+
3236
```ts
3337
const isr = new ISRHandler({
3438
indexHtml,
3539
invalidateSecretToken: 'MY_TOKEN', // replace with env secret key ex. process.env.REVALIDATE_SECRET_TOKEN
36-
enableLogging: !environment.production
40+
enableLogging: !environment.production,
3741
});
3842
```
3943

4044
3. Add invalidation url handler
45+
4146
```ts
4247
server.use(express.json());
43-
server.post("/api/invalidate", async (req, res) => await isr.invalidate(req, res));
48+
server.post(
49+
'/api/invalidate',
50+
async (req, res) => await isr.invalidate(req, res)
51+
);
4452
```
4553

4654
4. Replace Angular default server side rendering with ISR rendering
4755

4856
Replace
57+
4958
```ts
50-
server.get('*',
51-
(req, res) => {
52-
res.render(indexHtml, { req, providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }] });
53-
}
54-
);
59+
server.get('*', (req, res) => {
60+
res.render(indexHtml, {
61+
req,
62+
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
63+
});
64+
});
5565
```
66+
5667
with
5768

5869
```ts
59-
server.get('*',
70+
server.get(
71+
'*',
6072
// Serve page if it exists in cache
6173
async (req, res, next) => await isr.serveFromCache(req, res, next),
6274
// Server side render the page and add to cache if needed
63-
async (req, res, next) => await isr.render(req, res, next),
75+
async (req, res, next) => await isr.render(req, res, next)
6476
);
6577
```
6678

6779
You can also pass `providers` to each of the `ISRHandler` methods.
6880

6981
```ts
70-
server.get('*',
71-
...
72-
async (req, res, next) => await isr.render(req, res, next, {
82+
server.get(
83+
'*',
84+
...async (req, res, next) =>
85+
await isr.render(req, res, next, {
7386
providers: [
7487
{ provide: APP_BASE_HREF, useValue: req.baseUrl }, // <-- Needs to be provided when passing providers
7588
{ provide: CUSTOM_TOKEN, useValue: 'Hello from ISR' },
76-
CustomService
77-
]
78-
}),
89+
CustomService,
90+
],
91+
})
7992
);
8093
```
8194

8295
It is also possible to pass a `modifyCachedHtml` or `modifyGeneratedHtml` callbacks to the `ISRHandler` methods.
8396
These methods provide a way to modify the html served from cache or the html that is generated on the fly.
8497

8598
**Important:** Use these methods with caution as the logic written can increase the processing time.
99+
86100
```ts
87-
server.get('*',
101+
server.get(
102+
'*',
88103
// Serve page if it exists in cache
89-
async (req, res, next) => await isr.serveFromCache(req, res, next, {
90-
modifyCachedHtml: (req, cachedHtml) => {
104+
async (req, res, next) =>
105+
await isr.serveFromCache(req, res, next, {
106+
modifyCachedHtml: (req, cachedHtml) => {
91107
return `${cachedHtml}<!-- Hello, I'm a modification to the original cache! -->`;
92-
}
93-
}),
108+
},
109+
}),
94110
// Server side render the page and add to cache if needed
95-
async (req, res, next) => await isr.render(req, res, next, {
96-
modifyGeneratedHtml: (req, html) => {
97-
return `${html}<!-- Hello, I'm modifying the generatedHtml before caching it! -->`
98-
}
99-
}),
111+
async (req, res, next) =>
112+
await isr.render(req, res, next, {
113+
modifyGeneratedHtml: (req, html) => {
114+
return `${html}<!-- Hello, I'm modifying the generatedHtml before caching it! -->`;
115+
},
116+
})
100117
);
101118
```
102119

@@ -105,6 +122,7 @@ ISRHandler provides `APP_BASE_HREF` by default. And if you want pass `providers`
105122
5. Add `revalidate` key in route data
106123

107124
Example:
125+
108126
```ts
109127
{
110128
path: "example",
@@ -115,23 +133,20 @@ Example:
115133

116134
> **NOTE:** Routes that don't have revalidate key in data won't be handled by ISR. They will fallback to Angular default server side rendering pipeline.
117135
118-
119136
6. Register providers
120137
To register the ngx-isr providers, you can either import `NgxIsrModule` in your `AppServerModule` or provide `provideISR` in your `AppServerModule` providers.
121138

122139
Or, if you are in a standalone app, you can register the providers in your `app.config.server.ts` file.
123140

124-
125141
- Register using `NgxIsrModule`
126142

127143
```ts
128144
import { NgxIsrModule } from 'ngx-isr/server'; // <-- Import module from library
129145

130146
@NgModule({
131147
imports: [
132-
...
133-
NgxIsrModule.forRoot() // <-- Use it in module imports
134-
]
148+
...NgxIsrModule.forRoot(), // <-- Use it in module imports
149+
],
135150
})
136151
export class AppServerModule {}
137152
```
@@ -143,8 +158,8 @@ import { provideISR } from 'ngx-isr/server';
143158

144159
@NgModule({
145160
providers: [
146-
provideISR() // <-- Use it in module providers
147-
]
161+
provideISR(), // <-- Use it in module providers
162+
],
148163
})
149164
export class AppServerModule {}
150165
```
@@ -157,7 +172,7 @@ import { provideISR } from 'ngx-isr/server';
157172
const serverConfig: ApplicationConfig = {
158173
providers: [
159174
provideServerRendering(),
160-
provideISR() // <-- Use it in config providers
175+
provideISR(), // <-- Use it in config providers
161176
],
162177
};
163178
```
@@ -174,6 +189,7 @@ When registering the providers, `NgxIsrService` will be initialized and will sta
174189
- feat: separate the library into secondary entry points for server and browser
175190

176191
### BREAKING CHANGES:
192+
177193
Imports now should be done from `ngx-isr/server` and `ngx-isr/browser` instead of `ngx-isr`;
178194

179195
```ts
@@ -191,15 +207,18 @@ import { provideISR } from 'ngx-isr/server';
191207
```
192208

193209
Things exported from `ngx-isr/server`:
210+
194211
- `NgxIsrModule`
195212
- `provideISR`
196213
- `ISRHandler`
197214
- `FileSystemCacheHandler` and `FileSystemCacheOptions`
198215

199216
Things exported from `ngx-isr/browser`:
217+
200218
- `NgxIsrService`
201219

202220
Things exported from `ngx-isr/models`:
221+
203222
- `CacheHandler`
204223
- `CacheISRConfig` (renamed from `ISROptions`)
205224
- `CacheData`
@@ -224,12 +243,15 @@ Things exported from `ngx-isr/models`:
224243
- feat: Introduce `RouteISRConfig` interface for better type safety in route data
225244

226245
How to use it?
246+
227247
```ts
228-
const routes: Rotues = [{
229-
path: 'home',
230-
component: HomeComponent,
231-
data: { revalidate: 0 } as RouteISRConfig // 👈 Add type to route data
232-
}];
248+
const routes: Rotues = [
249+
{
250+
path: 'home',
251+
component: HomeComponent,
252+
data: { revalidate: 0 } as RouteISRConfig, // 👈 Add type to route data
253+
},
254+
];
233255
```
234256

235257
- feat: Added build id support
@@ -247,16 +269,19 @@ Things exported from `ngx-isr/models`:
247269
What we can do is to set field in the environment file called `buildId` and set it to: `new Date().getTime(),`.
248270

249271
Ex. environment.ts:
272+
250273
```ts
251274
export const environment = {
252275
production: false,
253276
buildId: new Date().getTime() + '', // We need to convert it to string because the buildId is a string
254277
};
255278
```
279+
256280
This way we will have a unique build id for each build because the buildId will evaluated at build time.
257281
Then, we pass the build id to the ISRHandler constructor.
258282

259283
Ex. server.ts:
284+
260285
```ts
261286
import { environment } from './src/environments/environment';
262287

@@ -268,15 +293,16 @@ Things exported from `ngx-isr/models`:
268293

269294
- fix: Fixed a bug where the cache was not invalidated when the build id changed
270295

271-
272296
### Breaking changes:
273-
- `ISROptions` is being deprecated. Use `CacheISRConfig` instead.
274297

298+
- `ISROptions` is being deprecated. Use `CacheISRConfig` instead.
275299

276300
## Version 0.5.2
277-
* feat: Migrate repository to nx workspace
278-
* feat: Added `provideISR` provider function
279-
* chore: Update example RedisCacheHandler to use a prefix
301+
302+
- feat: Migrate repository to nx workspace
303+
- feat: Added `provideISR` provider function
304+
- chore: Update example RedisCacheHandler to use a prefix
280305

281306
## License
307+
282308
MIT

libs/isr-move/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
const server = require('../dist/docs/server/main');
22

3-
module.exports = server.app();
3+
module.exports = server.app();

libs/isr-move/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,3 @@
8989
"@nx/angular": "16.2.1"
9090
}
9191
}
92-

0 commit comments

Comments
 (0)