Skip to content
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

Relative URLs are not converted to absolute URLs in angular universal. #1994

Closed
1 of 5 tasks
TheJLifeX opened this issue Feb 13, 2021 · 4 comments
Closed
1 of 5 tasks

Comments

@TheJLifeX
Copy link

TheJLifeX commented Feb 13, 2021

🐞 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

Add angular universal.

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
@alan-agius4
Copy link
Collaborator

Duplicate of angular/angular#51626

@alan-agius4
Copy link
Collaborator

Thanks for the reproduction and detailed report anyways.

Much appreciated that you took time doing a good report. It’s unfortunate that you didn’t find the duplicate issue before posting.

@neilhem
Copy link

neilhem commented Feb 25, 2021

The same problem with @nguniversal/express-engine@11.2.0

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants