-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Tailored error message for custom host #32056
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
base: main
Are you sure you want to change the base?
Conversation
…pp by custom hostname Add custom middleware for to present an Angular-tailored message Fix angular#32028
| @@ -0,0 +1,116 @@ | |||
| /** | |||
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 seems to change the behaviour for a number of valid cases.
Example:
http://foo.localhostwill now be marked as invalid- When adding allowed hosts, all sub-domains will also be marked as valid, but with this change they will be marked as invalid.
- Accessing the app with an external IP, will now be marked as invalid.
My suggestion would be that instead of recreating the middleware, just replace the response.
const middlewareStack = server.middlewares.stack;
const idx = middlewareStack.findIndex(({handle}) =>
handle.name.startsWith('hostValidationMiddleware'),
);
if (idx !== -1) {
const middleware = middlewareStack[idx];
const originalHandle = middleware.handle;
middleware.handle = function angularHostValidationMiddleware(req, res, next) {
originalHandle(
req,
{
writeHead: res.writeHead.bind(res),
end: () => res.end('Error message.'),
},
next,
);
};
}| <body> | ||
| <div class="box"> | ||
| <h1>Blocked request. This host ("${hostname}") is not allowed.</h1> | ||
| <p>The Angular development server only responds to local hosts by default.</p> |
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 not actually fully true, as you can get a response via the external IP address.
| <p>The Angular development server only responds to local hosts by default.</p> |
| .box{max-width:760px;margin:0 auto} | ||
| h1{font-size:1.5rem;margin-bottom:.75rem} | ||
| p{margin:.5rem 0} | ||
| .muted{color:#6b7280} |
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.
Unused
| .muted{color:#6b7280} |
| </style> | ||
| </head> | ||
| <body> | ||
| <div class="box"> |
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.
Optional NIT
| <div class="box"> | |
| <main> |
Add custom middleware for to present an Angular-tailored message
Fix #32028
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?
The error message thrown when the Angular app is served via a custom hostname is incorrect/misleading
Issue Number: #32028
What is the new behavior?
Add custom middleware for to present an Angular-tailored message when angular served by ngrok
Does this PR introduce a breaking change?