| 232 | } |
| 233 | |
| 234 | async render( |
| 235 | req: Request, |
| 236 | res: Response, |
| 237 | next: NextFunction, |
| 238 | config?: RenderConfig, |
| 239 | ): Promise<Response | void> { |
| 240 | // TODO: remove this in a major as a BREAKING CHANGE |
| 241 | if (config?.modifyGeneratedHtml) { |
| 242 | if (this.isrConfig.modifyGeneratedHtml !== undefined) { |
| 243 | console.warn( |
| 244 | 'You can only specify `modifyGeneratedHtml` once. The one in render function will be removed in the next version.', |
| 245 | ); |
| 246 | } |
| 247 | const patchedModifyFn: ModifyHtmlCallbackFn = ( |
| 248 | req: Request, |
| 249 | html: string, |
| 250 | ) => { |
| 251 | return config.modifyGeneratedHtml?.(req, html) || html; |
| 252 | }; |
| 253 | this.isrConfig['modifyGeneratedHtml'] = patchedModifyFn; |
| 254 | } |
| 255 | |
| 256 | try { |
| 257 | const result = await this.cacheGeneration.generate( |
| 258 | req, |
| 259 | res, |
| 260 | config?.providers, |
| 261 | 'generate', |
| 262 | ); |
| 263 | if (!result) { |
| 264 | throw new Error('Error while generating the page!'); |
| 265 | } else { |
| 266 | return res.send(result.html); |
| 267 | } |
| 268 | } catch (error) { |
| 269 | next(); |
| 270 | } |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | const extractDataFromBody = ( |