Skip to content

Commit 3072e2e

Browse files
committed
fixup! docs: remove unneeded code from universal example/guide
1 parent 0d84b07 commit 3072e2e

3 files changed

Lines changed: 5 additions & 82 deletions

File tree

aio/content/examples/universal/src/app/absolute-url.interceptor.ts

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,17 @@
1-
// #docplaster
2-
// #docregion absolute-url-interceptor
3-
import {HTTP_INTERCEPTORS} from '@angular/common/http';
4-
// #enddocregion absolute-url-interceptor
51
import { NgModule } from '@angular/core';
62
import { ServerModule } from '@angular/platform-server';
73

8-
// #docregion absolute-url-interceptor
9-
import {AbsoluteUrlInterceptor} from './absolute-url.interceptor';
10-
// #enddocregion absolute-url-interceptor
114
import { AppModule } from './app.module';
125
import { AppComponent } from './app.component';
136

14-
// #docplaster ...
15-
// #docregion absolute-url-interceptor
167
@NgModule({
17-
// #enddocregion absolute-url-interceptor
188
imports: [
199
AppModule,
2010
ServerModule,
2111
],
22-
// #docplaster
23-
// #docregion absolute-url-interceptor
2412
providers: [
2513
// Add server-only providers here.
26-
// #docplaster
27-
// #enddocregion absolute-url-interceptor
28-
//
29-
// NOTE:
30-
// This interceptor is not needed for this example app. It is only included here as an
31-
// illustration of how to include server-only providers to an app.
32-
// #docregion absolute-url-interceptor
33-
{
34-
provide: HTTP_INTERCEPTORS,
35-
useClass: AbsoluteUrlInterceptor,
36-
multi: true,
37-
},
3814
],
39-
// #enddocregion absolute-url-interceptor
4015
bootstrap: [AppComponent],
41-
// #docplaster ...
42-
// #docregion absolute-url-interceptor
4316
})
4417
export class AppServerModule {}
45-
// #enddocregion absolute-url-interceptor

aio/content/guide/universal.md

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -279,24 +279,9 @@ So, you don't need to do anything to make relative URLs work on the server.
279279

280280
If, for some reason, you are not using an `@nguniversal/*-engine` package, you may need to handle it yourself.
281281

282-
One solution would be to provide the full URL to your application on the server (e.g. as a server-side only extra provider) and write an interceptor that can retrieve this value and prepend it to the request URL.
283-
How to provide the full URL to requests depends on what you are using to render the app on the server-side and is outside the scope of this guide.
282+
There are several ways to achieve that.
283+
The recommended solution, which is also the least intrusive as it does not require any changes to the app, is to pass the full request URL to the `options` argument of [renderModule()](api/platform-server/renderModule) or [renderModuleFactory()](api/platform-server/renderModuleFactory) (depending on what you use to render `AppServerModule` on the server).
284+
Here, "request URL" refers to the URL of the request as a response to which the app is being rendered on the server.
285+
For example, if the client requested `https://my-server.com/dashboard` and you are rendering the app on the server to respond to that request, `options.url` should be set to `https://my-server.com/dashboard`.
284286

285-
This is half of the work.
286-
The other half is using the provided full URL in the app.
287-
This can be achieved by creating an [HttpInterceptor](api/common/http/HttpInterceptor).
288-
289-
<code-example
290-
header="src/app/absolute-url.interceptor.ts"
291-
path="universal/src/app/absolute-url.interceptor.ts">
292-
</code-example>
293-
294-
This interceptor needs to be provided to the app on the server only, which can be done by adding it to the providers array of `AppServerModule`.
295-
296-
<code-example
297-
header="src/app/app.server.module.ts"
298-
path="universal/src/app/app.server.module.ts"
299-
region="absolute-url-interceptor">
300-
</code-example>
301-
302-
Now, on every HTTP request made on the server, this interceptor will fire and replace the request URL with the absolute URL using the provided `fullUrl`.
287+
Now, on every HTTP request made as part of rendering the app on the server, Angular will be able to correctly resolve the request URL to an absolute URL, using the provided `options.url`.

0 commit comments

Comments
 (0)