Skip to content

Commit 07623ca

Browse files
AndrewKushniralxhub
authored andcommitted
docs: update SSR docs (angular#52408)
This commit updates the `ssr.md` file to restructure (and simplify) SSR docs. PR Close angular#52408
1 parent d122fc4 commit 07623ca

File tree

3 files changed

+93
-212
lines changed

3 files changed

+93
-212
lines changed

aio/content/examples/ssr/server.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
// #docplaster
22

3-
import { APP_BASE_HREF } from '@angular/common';
4-
import { CommonEngine } from '@angular/ssr';
3+
import {APP_BASE_HREF} from '@angular/common';
4+
import {CommonEngine} from '@angular/ssr';
55
import express from 'express';
6-
import { fileURLToPath } from 'node:url';
7-
import { dirname, join, resolve } from 'node:path';
6+
import {dirname, join, resolve} from 'node:path';
7+
import {fileURLToPath} from 'node:url';
8+
89
import bootstrap from './src/main.server';
910

1011
// The Express app is exported so that it can be used by serverless Functions.
@@ -13,42 +14,34 @@ export function app(): express.Express {
1314
const serverDistFolder = dirname(fileURLToPath(import.meta.url));
1415
const browserDistFolder = resolve(serverDistFolder, '../browser');
1516
const indexHtml = join(serverDistFolder, 'index.server.html');
16-
// #docregion CommonEngine
1717
const commonEngine = new CommonEngine();
18-
// #enddocregion CommonEngine
1918

2019
server.set('view engine', 'html');
2120
server.set('views', browserDistFolder);
2221

23-
// #docregion data-request
2422
// TODO: implement data requests securely
2523
// Serve data from URLS that begin "/api/"
2624
server.get('/api/**', (req, res) => {
2725
res.status(404).send('data requests are not yet supported');
2826
});
29-
// #enddocregion data-request
30-
// #docregion static
3127
// Serve static files from /browser
32-
server.get('*.*', express.static(browserDistFolder, {
33-
maxAge: '1y'
34-
}));
35-
// #enddocregion static
28+
server.get('*.*', express.static(browserDistFolder, {maxAge: '1y'}));
3629

3730
// #docregion navigation-request
3831
// All regular routes use the Angular engine
3932
server.get('*', (req, res, next) => {
40-
const { protocol, originalUrl, baseUrl, headers } = req;
33+
const {protocol, originalUrl, baseUrl, headers} = req;
4134

4235
commonEngine
43-
.render({
44-
bootstrap,
45-
documentFilePath: indexHtml,
46-
url: `${protocol}://${headers.host}${originalUrl}`,
47-
publicPath: browserDistFolder,
48-
providers: [{ provide: APP_BASE_HREF, useValue: req.baseUrl }],
49-
})
50-
.then((html) => res.send(html))
51-
.catch((err) => next(err));
36+
.render({
37+
bootstrap,
38+
documentFilePath: indexHtml,
39+
url: `${protocol}://${headers.host}${originalUrl}`,
40+
publicPath: browserDistFolder,
41+
providers: [{provide: APP_BASE_HREF, useValue: req.baseUrl}],
42+
})
43+
.then((html) => res.send(html))
44+
.catch((err) => next(err));
5245
});
5346
// #enddocregion navigation-request
5447

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,26 @@
11
// #docplaster
2-
import { importProvidersFrom } from '@angular/core';
3-
import { provideProtractorTestingSupport } from '@angular/platform-browser';
4-
import { provideClientHydration} from '@angular/platform-browser';
5-
import { ApplicationConfig } from '@angular/core';
6-
import { provideRouter } from '@angular/router';
7-
import { provideHttpClient, withFetch } from '@angular/common/http';
2+
import {provideHttpClient, withFetch} from '@angular/common/http';
3+
import {ApplicationConfig, importProvidersFrom} from '@angular/core';
4+
import {provideClientHydration, provideProtractorTestingSupport} from '@angular/platform-browser';
5+
import {provideRouter} from '@angular/router';
6+
import {HttpClientInMemoryWebApiModule} from 'angular-in-memory-web-api';
87

9-
import { routes } from './app.routes';
10-
11-
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
12-
import { InMemoryDataService } from './in-memory-data.service';
8+
import {routes} from './app.routes';
9+
import {InMemoryDataService} from './in-memory-data.service';
1310

1411
export const appConfig: ApplicationConfig = {
1512
providers: [
1613
provideRouter(routes),
17-
// TODO: Enable using Fetch API when disabling `HttpClientInMemoryWebApiModule`.
18-
provideHttpClient(/* withFetch()*/ ),
19-
provideClientHydration(),
20-
provideProtractorTestingSupport(), // essential for e2e testing
14+
// TODO: Enable using Fetch API when disabling `HttpClientInMemoryWebApiModule`.
15+
provideHttpClient(/* withFetch()*/), provideClientHydration(),
16+
provideProtractorTestingSupport(), // essential for e2e testing
2117

22-
// #docregion in-mem
2318
// TODO: Remove from production apps
2419
importProvidersFrom(
25-
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests
26-
// and returns simulated server responses.
27-
// Remove it when a real server is ready to receive requests.
28-
HttpClientInMemoryWebApiModule.forRoot(
29-
InMemoryDataService, { dataEncapsulation: false }
30-
)
31-
),
32-
// #enddocregion in-mem
20+
// The HttpClientInMemoryWebApiModule module intercepts HTTP requests
21+
// and returns simulated server responses.
22+
// Remove it when a real server is ready to receive requests.
23+
HttpClientInMemoryWebApiModule.forRoot(InMemoryDataService, {dataEncapsulation: false})),
3324
// ...
3425
],
3526
};

0 commit comments

Comments
 (0)