@@ -341,6 +341,17 @@ export function withAppShell(
341341 } ;
342342}
343343
344+ /**
345+ * Options for configuring server-side rendering.
346+ */
347+ interface ServerRenderingOptions {
348+ /**
349+ * The maximum allowed response body size when using the Fetch API.
350+ * @default 1MB
351+ */
352+ maxResponseBodySize : number ;
353+ }
354+
344355/**
345356 * Configures server-side rendering for an Angular application.
346357 *
@@ -379,10 +390,71 @@ export function withAppShell(
379390 */
380391export function provideServerRendering (
381392 ...features : ServerRenderingFeature < ServerRenderingFeatureKind > [ ]
393+ ) : EnvironmentProviders ;
394+
395+ /**
396+ * Configures server-side rendering for an Angular application with additional options.
397+ *
398+ * This function sets up the necessary providers for server-side rendering, including
399+ * support for server routes and app shell. It combines features configured using
400+ * `withRoutes` and `withAppShell` to provide a comprehensive server-side rendering setup.
401+ *
402+ * @param options - Configuration options for server-side rendering.
403+ * @param features - Optional features to configure additional server rendering behaviors.
404+ * @returns An `EnvironmentProviders` instance with the server-side rendering configuration.
405+ *
406+ * @example
407+ * Basic example of how you can enable server-side rendering with options in your application
408+ * when using the `bootstrapApplication` function:
409+ *
410+ * ```ts
411+ * import { bootstrapApplication, BootstrapContext } from '@angular/platform-browser';
412+ * import { provideServerRendering, withRoutes, withAppShell } from '@angular/ssr';
413+ * import { AppComponent } from './app/app.component';
414+ * import { SERVER_ROUTES } from './app/app.server.routes';
415+ * import { AppShellComponent } from './app/app-shell.component';
416+ *
417+ * const bootstrap = (context: BootstrapContext) =>
418+ * bootstrapApplication(AppComponent, {
419+ * providers: [
420+ * provideServerRendering(
421+ * { maxResponseBodySize: 1024 * 1024 }, // 1MB limit
422+ * withRoutes(SERVER_ROUTES),
423+ * withAppShell(AppShellComponent),
424+ * ),
425+ * ],
426+ * }, context);
427+ *
428+ * export default bootstrap;
429+ * ```
430+ * @see {@link withRoutes } configures server-side routing
431+ * @see {@link withAppShell } configures the application shell
432+ */
433+ export function provideServerRendering (
434+ options : ServerRenderingOptions ,
435+ ...features : ServerRenderingFeature < ServerRenderingFeatureKind > [ ]
436+ ) : EnvironmentProviders ;
437+ export function provideServerRendering (
438+ ...args :
439+ | ServerRenderingFeature < ServerRenderingFeatureKind > [ ]
440+ | [ ServerRenderingOptions , ...ServerRenderingFeature < ServerRenderingFeatureKind > [ ] ]
382441) : EnvironmentProviders {
442+ let options : ServerRenderingOptions | undefined ;
443+ let features : ServerRenderingFeature < ServerRenderingFeatureKind > [ ] ;
444+ if ( hasOptions ( args ) ) {
445+ const [ first , ...rest ] = args ;
446+ options = first ;
447+ features = rest ;
448+ } else {
449+ features = args ;
450+ }
451+
452+ const providers : ( Provider | EnvironmentProviders ) [ ] = [
453+ provideServerRenderingPlatformServer ( options ) ,
454+ ] ;
455+
383456 let hasAppShell = false ;
384457 let hasServerRoutes = false ;
385- const providers : ( Provider | EnvironmentProviders ) [ ] = [ provideServerRenderingPlatformServer ( ) ] ;
386458
387459 for ( const { ɵkind, ɵproviders } of features ) {
388460 hasAppShell ||= ɵkind === ServerRenderingFeatureKind . AppShell ;
@@ -399,3 +471,16 @@ export function provideServerRendering(
399471
400472 return makeEnvironmentProviders ( providers ) ;
401473}
474+
475+ /**
476+ * Checks if the first element of args is a `ServerRenderingOptions` object.
477+ */
478+ function hasOptions (
479+ args :
480+ | ServerRenderingFeature < ServerRenderingFeatureKind > [ ]
481+ | [ ServerRenderingOptions , ...ServerRenderingFeature < ServerRenderingFeatureKind > [ ] ] ,
482+ ) : args is [ ServerRenderingOptions , ...ServerRenderingFeature < ServerRenderingFeatureKind > [ ] ] {
483+ const value = args [ 0 ] ;
484+
485+ return ! ! value && typeof value === 'object' && ! ( 'ɵkind' in value ) ;
486+ }
0 commit comments