Relative URLs are not converted to absolute URLs in angular universal. #1994
Description
🐞 Bug report
What modules are related to this issue?
- aspnetcore-engine
- builders
- common
- express-engine
- hapi-engine
Is this a regression?
no
Description
According to the official angular documentation, when running on the server, relative URLs such as api/heroes
should be automatically converted to absolute URLs (for example, https://my-server.com/api/heroes
in production and (I guess) http://localhost:4200/api/heroes
in development), if you are using one of the @nguniversal/*-engine packages (such as @nguniversal/express-engine).
But this is not the case (for the @nguniversal/express-engine package that I tested).
For the following request, when running on the server (see Minimal Reproduction
below),
this.httpClient.get('api').subscribe((res) => {
console.log(res);
});
you get the following error.
ERROR NetworkError
at XMLHttpRequest.send (...)
at Observable._subscribe (...)
at Observable._trySubscribe (...)
...
Thank you in advance for considering this issue.
🔬 Minimal Reproduction
Clone this minimal GitHub repository
npm install
npm run dev:ssr
Or if you want to reproduce it manually step by step.
npm install @angular/cli@11.2.0 -g
ng new my-app
Navigate to the newly created app.
cd my-app
ng add @nguniversal/express-engine
Copy and paste all changes made in this commit.
Run the app then open http://localhost:4200/
on your browser and look at the console on the server.
npm run dev:ssr
🔥 Exception or Error
ERROR NetworkError
at XMLHttpRequest.send (...)
at Observable._subscribe (...)
at Observable._trySubscribe (...)
...
🌍 Your Environment
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 11.2.0
Node: 12.16.1
OS: win32 x64
Angular: 11.2.0
... animations, cli, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, platform-server
... router
Ivy Workspace: Yes
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1102.0
@angular-devkit/build-angular 0.1102.0
@angular-devkit/core 11.2.0
@angular-devkit/schematics 11.2.0
@nguniversal/builders 11.1.2
@nguniversal/express-engine 11.1.2
@schematics/angular 11.2.0
@schematics/update 0.1102.0
rxjs 6.6.3
typescript 4.1.5