Repository navigation
Conversation
Requests whose path starts with one of these prefixes are left to the next handler instead of being rendered by a catch-all route, which could repeat a request the application sends to its own host without bound.
There was a problem hiding this comment.
Code Review
This pull request introduces the excludedPathPrefixes option to AngularAppEngine, allowing developers to specify path prefixes (such as API routes) that the engine should ignore and pass to the next handler. The implementation includes logic to normalize, decode, and match these prefixes against request paths, taking localized applications and base hrefs into account, along with comprehensive unit tests. The review feedback focuses on optimizing the request-handling hot path by precomputing the normalized base path and locale prefixes during initialization, and adding a fast-path check in decodePath to avoid unnecessary string operations when no percent-encoded characters are present.
|
Thanks for the thorough investigation in angular/angular#72223 and for putting this PR together. We are going to close this as we do not want to add
As you noted in angular/angular#72223, supporting ports in Thanks again for all the research and testing on this! |
PR Checklist
Please check to confirm your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
A catch-all server route (
**) renders any path that nothing else answered. When a page requests one of its own API paths during SSR and that request reaches the SSR server instead of the API, Angular renders it as a page, that render sends the same request again, and so on until the server runs out of memory.Issue Number: angular/angular#72223
What is the new behavior?
AngularAppEngineandAngularNodeAppEngineacceptexcludedPathPrefixes. A request whose path starts with one of them is never rendered:handle()resolves tonulland the next handler answers it.The check runs after the host validation and before the app is selected. Paths are compared decoded, and also without the base href and the locale, so
/en/api/usersmatches/apibut/apiaryand/docs/apidon't.It's opt-in. It doesn't try to detect the loop, it only takes away the paths that feed it, so no header is read and nothing a client sends changes the result.
Does this PR introduce a breaking change?
Other information
With the app from the issue and
['/api'], the request from the issue costs one render, also withwithXhr(), nativefetch,node:clusterand an extra proxy hop. Without the option the server runs out of memory in about 15 s.Not covered: a document without a
<base>element that requests the API with a path-relative URL (api/config). That resolves against the path of the page, which a prefix can't match. It's noted in the option's JSDoc.This doesn't replace angular/angular#72203. It's meant as an alternative for apps that can't list ports.