Skip to content

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

Closed

Description

@jagobagascon

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

Activity

  1. self-assigned this
    on Jun 27, 2024
  2. added
    freq1: low
    and removed
    freq1: low
    on Jun 27, 2024
  3. alan-agius4 commented on Jun 27, 2024

    @alan-agius4
    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.

  4. added 3 commits that reference this issue on Jun 28, 2024
    2788508
    d96f57c
    2c78e3c
  5. added 3 commits that reference this issue on Jun 28, 2024
    2d51e86
    27bd670
    9a1c059
  6. jagobagascon commented on Jun 28, 2024

    @jagobagascon
    Author

    Thank you for the quick fix!

  7. angular-automatic-lock-bot commented on Jul 29, 2024

    @angular-automatic-lock-bot

    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.

  8. locked and limited conversation to collaborators on Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

angular/build:dev-serverarea: @angular/buildfreq1: lowseverity3: brokentype: bug/fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions