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

serve: serving static files using vite differs from the previous builder #27949

Closed
1 task
jagobagascon opened this issue Jun 27, 2024 · 3 comments · Fixed by #27958
Closed
1 task

serve: serving static files using vite differs from the previous builder #27949

jagobagascon opened this issue Jun 27, 2024 · 3 comments · Fixed by #27958
Assignees

Comments

@jagobagascon
Copy link

Command

serve

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

No response

Description

We are migrating our project to Angular's new build system. It is the preferred option for new projects and we think migrating to it is a good idea. But we have found a small issue with how the static assets are served compared to the previous browser builder.

Our application requires a bunch of static files to work, and one of the html files is accessed using the parent folder name without a trailing slash: localhost:4200/oauth2redirect. Using the previous builder this was loading the oauth2redirect/index.html file.

After migrating to the new application builder, this same URI throws the following error:

Error: NG04002: Cannot match any routes. URL Segment: 'oauth2redirect'

This can be fixed by adding a trailing slash to the URI (localhost:4200/oauth2redirect/). But this would require updating our OAuth redirect uri. And since this is something already supported by other tools and platforms (Google Cloud Buckets for example), I think it may be a good idea to support it here as well.

Minimal Reproduction

Add some static index.html to an angular project:

src/
  app/...
  static/
    oauth2redirect/
      index.html
// angular.json
"assets": [
  {
    "glob": "**/*",
    "input": "src/static",
    "output": "/"
  }
]

Serve the app

ng serve

And try to load the file by using its parent folder.

All three URIs work with previous browser builder. And the first one fails with the new application builder.

localhost:4200/oauth2redirect # => error
localhost:4200/oauth2redirect/ # => loads the file
localhost:4200/oauth2redirect/index.hmtl # => loads the file

Exception or Error

No response

Your Environment

Angular CLI: 17.3.8
Node: 18.20.3
Package Manager: npm 10.8.1
OS: darwin arm64

Angular: 17.3.11
... animations, common, compiler, compiler-cli, core, forms
... language-service, localize, platform-browser
... platform-browser-dynamic, router, service-worker

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1703.8
@angular-devkit/build-angular   17.3.8
@angular-devkit/core            17.3.8
@angular-devkit/schematics      17.3.8
@angular/cdk                    17.3.10
@angular/cli                    17.3.8
@angular/material               17.3.10
@schematics/angular             17.3.8
rxjs                            7.8.1
typescript                      5.3.3
zone.js                         0.14.4

Anything else relevant?

No response

@alan-agius4 alan-agius4 self-assigned this Jun 27, 2024
@alan-agius4 alan-agius4 added type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken and removed type: bug/fix freq1: low Only reported by a handful of users who observe it rarely severity3: broken labels Jun 27, 2024
@alan-agius4
Copy link
Collaborator

I had a quick look at this, and what happens here is that express static will redirect to the / when the pathname is a directory by default but vite does not.

alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jun 28, 2024
…irectories

Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes angular#27949
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jun 28, 2024
…irectories

Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes angular#27949
alan-agius4 added a commit to alan-agius4/angular-cli that referenced this issue Jun 28, 2024
…irectories

Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes angular#27949
alan-agius4 added a commit that referenced this issue Jun 28, 2024
…irectories

Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes #27949

(cherry picked from commit 9a1c059)
alan-agius4 added a commit that referenced this issue Jun 28, 2024
…irectories

Prior to this commit, accessing a static asset directory without a trailing slash resulted in a 404 error. With this change, we now redirect to the path with a trailing slash, aligning with the behavior of express static.

Closes #27949

(cherry picked from commit 9a1c059)
@jagobagascon
Copy link
Author

Thank you for the quick fix!

@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 Jul 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants