docs: update universal guide and docs example to v9#36483
docs: update universal guide and docs example to v9#36483gkalpak wants to merge 11 commits intoangular:masterfrom
universal guide and docs example to v9#36483Conversation
|
You can preview 0fccbbf at https://pr36483-0fccbbf.ngbuilds.io/. |
0fccbbf to
8516692
Compare
universal guide and docs exampleuniversal guide and docs example to v9
|
You can preview 8516692 at https://pr36483-8516692.ngbuilds.io/. |
There was a problem hiding this comment.
| ### Using absolute URLs for server requests | |
| ### Using absolute URLs for HTTP (data) requests on the server |
There was a problem hiding this comment.
| intercept(req: HttpRequest<any>, next: HttpHandler) { | |
| intercept(req: HttpRequest<unknown>, next: HttpHandler) { |
Can you please use unknown whenever we can instead of any as any can lead to lots of type inference issues... thanks!
There was a problem hiding this comment.
I just move the code snippet from the guide to a file, so I kept the original code. I assume any was used to match the HttpInterceptor#intercept() signature (which features any).
In any case, this code is removed in the following fixup commit, so this doesn't really matter 😁
I'll merge the fixup commit into this one to avoid confusion.
IgorMinar
left a comment
There was a problem hiding this comment.
Reviewed-for: global-approvers
but let's have @aikidave also take a quick look to check the language. thanks!
8516692 to
3a5e1e7
Compare
3a5e1e7 to
11cbc21
Compare
|
You can preview 11cbc21 at https://pr36483-11cbc21.ngbuilds.io/. |
aikithoughts
left a comment
There was a problem hiding this comment.
A few suggestions to make the text a little shorter and easier to read.
There was a problem hiding this comment.
| So, you don't need to do anything to make relative URLs work on the server. | |
| You don't need to do anything to make relative URLs work on the server. |
There was a problem hiding this comment.
| 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). | |
| The recommended solution 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). This option is the least intrusive as it does not require any changes to the app, |
There was a problem hiding this comment.
| 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`. | |
| Now, on every HTTP request made as part of rendering the app on the server, Angular can correctly resolve the request URL to an absolute URL, using the provided `options.url`. |
There was a problem hiding this comment.
Unless I am missing something, it appears that we say that there are several ways to handle relative URLs, but only provide one, as it is the recommended way to do it. If that's the case, we can delete line 282.
…s example ZIP archive Previously, the `package.json` template used in the ZIP archive of the `universal` example that we offer for download missed the `build` npm script. This commit updates the template for the `universal` docs example to include the `build` npm script. NOTE: The `build` npm script is already included in `aio/tools/examples/shared/boilerplate/universal/package.json`, but it was removed by the example zipper.
11cbc21 to
928dd02
Compare
|
Thx, @aikidave! I've made the changes you suggested. |
alan-agius4
left a comment
There was a problem hiding this comment.
LGTM, from universal side. Thanks @gkalpak.
I noticed these minor styling issues while aligning the `universal` examples with the `toh-pt6` example (in a subsequent commit). PR Close #36483
As mentioned in the `universal` guide, the `toh-pt6` examples is the starting poitn for the `universal` example. However, the two examples had become out-of-sync, because some fixes/changes were made to the Tour-of-Heroes examples. This commit ports these changes to the `universal` example. PR Close #36483
… error in `universal` example (#36483) Previously, building the `universal` example failed with: ``` node_modules/@types/express/index.d.ts(90,50): error TS2694: Namespace '".../@types/express-serve-static-core/index"' has no exported member 'Params'. node_modules/@types/express/index.d.ts(90,64): error TS2694: Namespace '".../@types/express-serve-static-core/index"' has no exported member 'ParamsDictionary'. ``` This commit fixes the error by upgrading `@types/express-serve-static-core` to a newer version. See DefinitelyTyped/DefinitelyTyped#40905 for more details. PR Close #36483
Previously, there were no tests for the `universal` docs example. This meant that the project was not tested at all (not even ensuring that it can be built successfully). This commit adds e2e tests for the `universal` example (ported from `toh-pt6` and cleaned up) and also verifies that the project can be built successfully (including the server). PR Close #36483
In the past, server-side rendered apps needed to convert URLs used in API requests to absolute when rendering on the server. Originally, this was handled in the `universal` guide and corresponding example app by modifying the `HeroService` to use `APP_BASE_HREF` to derive the absolute URL. In #28956, the guide was updated to show an improved method: Specifying an `HttpInterceptor` that took care of converting the URLs to absolute. That interceptor was only provided when rendering the app on the server. By mistake, the corresponding example app was not updated along with the guide. Since `@nguniversal/*` v7.1.0, it is no longer necessary to convert the URLs to absolute inside the app. This is handled in the `@nguniversal` libs (see angular/universal#897). This commit updates the example app to remove unnecessary code and modifies the guide to mention the issue with absolute URLs, but explain that developers only need to worry about it when not using one of the `@nguniversal/*-engine` packages. PR Close #36483
…s example ZIP archive (#36483) Previously, the `package.json` template used in the ZIP archive of the `universal` example that we offer for download missed the `build` npm script. This commit updates the template for the `universal` docs example to include the `build` npm script. NOTE: The `build` npm script is already included in `aio/tools/examples/shared/boilerplate/universal/package.json`, but it was removed by the example zipper. PR Close #36483
I noticed these minor styling issues while aligning the `universal` examples with the `toh-pt6` example (in a subsequent commit). PR Close #36483
As mentioned in the `universal` guide, the `toh-pt6` examples is the starting poitn for the `universal` example. However, the two examples had become out-of-sync, because some fixes/changes were made to the Tour-of-Heroes examples. This commit ports these changes to the `universal` example. PR Close #36483
… error in `universal` example (#36483) Previously, building the `universal` example failed with: ``` node_modules/@types/express/index.d.ts(90,50): error TS2694: Namespace '".../@types/express-serve-static-core/index"' has no exported member 'Params'. node_modules/@types/express/index.d.ts(90,64): error TS2694: Namespace '".../@types/express-serve-static-core/index"' has no exported member 'ParamsDictionary'. ``` This commit fixes the error by upgrading `@types/express-serve-static-core` to a newer version. See DefinitelyTyped/DefinitelyTyped#40905 for more details. PR Close #36483
Previously, there were no tests for the `universal` docs example. This meant that the project was not tested at all (not even ensuring that it can be built successfully). This commit adds e2e tests for the `universal` example (ported from `toh-pt6` and cleaned up) and also verifies that the project can be built successfully (including the server). PR Close #36483
In the past, server-side rendered apps needed to convert URLs used in API requests to absolute when rendering on the server. Originally, this was handled in the `universal` guide and corresponding example app by modifying the `HeroService` to use `APP_BASE_HREF` to derive the absolute URL. In #28956, the guide was updated to show an improved method: Specifying an `HttpInterceptor` that took care of converting the URLs to absolute. That interceptor was only provided when rendering the app on the server. By mistake, the corresponding example app was not updated along with the guide. Since `@nguniversal/*` v7.1.0, it is no longer necessary to convert the URLs to absolute inside the app. This is handled in the `@nguniversal` libs (see angular/universal#897). This commit updates the example app to remove unnecessary code and modifies the guide to mention the issue with absolute URLs, but explain that developers only need to worry about it when not using one of the `@nguniversal/*-engine` packages. PR Close #36483
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
This PR updates the
universalguide and docs example to be aligned with what the v9 CLI generates. It also removes an obsolete section (and the corresponding code) and adds some tests for the example app.See the individual commit messages for more details.
Fixes #35289.
This was originally part of #34374 (and split off for easier reviewing).
Partially addresses: FW-1609