-
Notifications
You must be signed in to change notification settings - Fork 13
fix: update readme with installation notes for Angular 19 #223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,8 @@ This build plugin implements Angular Support on Netlify. | |
|
||
- [Installation and Configuration](#installation-and-configuration) | ||
- [Accessing `Request` and `Context` during Server-Side Rendering](#accessing-request-and-context-during-server-side-rendering) | ||
- [Customizing request handling](#customizing-request-handling) | ||
- [Request handling](#request-handling) | ||
- [Customizing request handling](#customizing-request-handling) | ||
- [Limitations](#limitations) | ||
- [CLI Usage](#cli-usage) | ||
- [Getting Help](#getting-help) | ||
|
@@ -26,18 +27,19 @@ This build plugin implements Angular Support on Netlify. | |
|
||
## Installation and Configuration | ||
|
||
Netlify automatically detects Angular projects and sets up the latest version of this plugin. There's no further configuration needed from Netlify users. | ||
Netlify automatically detects Angular projects and sets up the latest version of this plugin. | ||
|
||
### Manual Installation | ||
### For Angular 17 and Angular 18 | ||
|
||
If you need to pin down this plugin to a fixed version, install it manually. | ||
There's no further configuration needed from Netlify users. | ||
|
||
Create a `netlify.toml` in the root of your project. Your file should include the plugins section below: | ||
### For Angular 19 | ||
|
||
```toml | ||
[[plugins]] | ||
package = "@netlify/angular-runtime" | ||
``` | ||
If you are using Server-Side Rendering you will need to install Angular Runtime in your Angular project to be able to import required utilities to successfully deploy request handler to Netlify. See [Manual Installation](#manual-installation) for installations details. See [Request handling](#request-handling) for more information about request handler. | ||
|
||
### Manual Installation | ||
|
||
If you need to pin this plugin to a specific version or if you are using Server-Side Rendering with Angular 19, you will need to install the plugin manually. | ||
|
||
Install it via your package manager: | ||
|
||
|
@@ -47,9 +49,6 @@ npm install -D @netlify/angular-runtime | |
yarn add -D @netlify/angular-runtime | ||
``` | ||
|
||
Read more about [file-based plugin installation](https://docs.netlify.com/configure-builds/build-plugins/#file-based-installation) | ||
in our docs. | ||
|
||
## Accessing `Request` and `Context` during Server-Side Rendering | ||
|
||
During server-side rendering (SSR), you can access the incoming `Request` object and the Netlify-specific `Context` object via providers: | ||
|
@@ -102,9 +101,15 @@ export class FooComponent { | |
} | ||
``` | ||
|
||
## Customizing request handling | ||
## Request handling | ||
|
||
Starting with Angular@19. The build plugin makes use of `server.ts` file to handle requests. The default Angular scaffolding does generate incompatible code for Netlify so build plugin will swap it for compatible `server.ts` file for you automatically if it detects default one being used. If you need to customize the request handling, you can do so by copying one of code snippets below to your `server.ts` file. | ||
Starting with Angular@19. The build plugin makes use of the `server.ts` file to handle requests. The default Angular scaffolding generates incompatible code for Netlify so the build plugin will swap it for compatible `server.ts` file automatically if it detects default version being used. | ||
|
||
Make sure you have `@netlify/angular-runtime` version 2.2.0 or later installed in your project. Netlify compatible `server.ts` file imports utilities from this package and Angular Compiler need to be able to resolve it and it can only do that if it's installed in your project and not when it's auto-installed by Netlify. | ||
|
||
### Customizing request handling | ||
|
||
If you need to customize the request handling, you can do so by copying one of code snippets below to your `server.ts` file. | ||
|
||
If you did not opt into the App Engine Developer Preview: | ||
|
||
|
@@ -115,6 +120,13 @@ import { render } from '@netlify/angular-runtime/common-engine' | |
const commonEngine = new CommonEngine() | ||
|
||
export async function netlifyCommonEngineHandler(request: Request, context: any): Promise<Response> { | ||
// Example API endpoints can be defined here. | ||
// Uncomment and define endpoints as necessary. | ||
// const pathname = new URL(request.url).pathname; | ||
// if (pathname = '/api/hello') { | ||
// return Response.json({ message: 'Hello from the API' }); | ||
// } | ||
|
||
Comment on lines
+123
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taking a page from what Angular scaffolds with commented out example ( https://github.com/angular/angular-cli/blob/main/packages/schematics/angular/ssr/files/application-builder/server.ts.template#L17-L27 ) overall unrelated to rest of changes and can drop it from here |
||
return await render(commonEngine) | ||
} | ||
``` | ||
|
@@ -130,6 +142,13 @@ const angularAppEngine = new AngularAppEngine() | |
export async function netlifyAppEngineHandler(request: Request): Promise<Response> { | ||
const context = getContext() | ||
|
||
// Example API endpoints can be defined here. | ||
// Uncomment and define endpoints as necessary. | ||
// const pathname = new URL(request.url).pathname; | ||
// if (pathname = '/api/hello') { | ||
// return Response.json({ message: 'Hello from the API' }); | ||
// } | ||
|
||
const result = await angularAppEngine.handle(request, context) | ||
return result || new Response('Not found', { status: 404 }) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is no longer needed with autoinstallation in CLI