Skip to content

Only serve index.html for path patterns known to match route paths #67053

Open

Description

@DanTup

Using current master:

  • flutter create foo
  • cd foo
  • flutter run -d chrome
  • when the browser opens, delete the # from the URL and add /missing

The response returns a 200 status with HTML for the app, but I'd expect a 404.

Screenshot 2020-10-01 at 15 39 35

Activity

  1. jonahwilliams commented on Oct 1, 2020

    @jonahwilliams
    Contributor
  2. added
    platform-webWeb applications specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Oct 1, 2020
  3. Vitor-Bukovitz commented on Oct 1, 2020

    @Vitor-Bukovitz

    Same here but I'm getting my website regardless of what comes after /, e.g: https://www.mywebsite.com/12398ueushadihsa12iu
    After it loads the URL becomes like this: https://www.mywebsite.com/12398ueushadihsa12iu#/

  4. mdebbar commented on Oct 1, 2020

    @mdebbar
    Contributor

    This is WAI. The reason we made it this way is to prepare to support regular paths in flutter web apps (paths without the #). So if you configure your app to use PathUrlStrategy (instead of the old HashUrlStrategy) you can visit: http://localhost:8080/profile which loads your app, and use /profile as a route name for the Navigator.

    That said, I would like to learn more if this is causing any issues for you.

  5. DanTup commented on Oct 5, 2020

    @DanTup
    ContributorAuthor

    It caused an issue in DevTools, as it was trying to check whether it was running through its own server (so sending a request to the server to api/ping and checking for a 200 status). That's not a significant issue though and it was worked around by checking the contentType was not text/html (flutter/devtools#2396). I don't think if this kind of thing is common.

    I hadn't considered PathUrlStrategy - I think supporting that is more valuable than avoiding the DevTools workaround though (and we could work around it other says, like inspecting the response from the API is a known good value) so I wouldn't change this if that's the only issue.

    Thanks!

  6. DanTup commented on Oct 5, 2020

    @DanTup
    ContributorAuthor

    @mdebbar out of interest, would serving a 404 status but still the page content work? It might work better if people are sending API calls and checking status codes, and I don't think it'd make any difference to the users refreshing the pages in their browser?

  7. mdebbar commented on Oct 7, 2020

    @mdebbar
    Contributor

    @DanTup serving 404 tells the browser (and the user) that the content they are requesting doesn't exist. We can still serve some content with 404, but that content is supposed to be the 404 page.

    Would it be possible to serve your flutter app on http://localhost:12345/devtools/ (instead of http://localhost:12345/)? You can do that by adding <base href="/devtools/"> to the web/index.html file. If you do this, all requests that aren't prefixed with /devtools/ will get a 404 response. So your /api/ping request will receive 404 response as you expect.

    Let me know if this workaround is okay for you.

  8. DanTup commented on Oct 7, 2020

    @DanTup
    ContributorAuthor

    @mdebbar I made another workaround which inspects the response to api/ping is the content we sent which is probably better. The 404 was really an idea in case other people are doing the same sort of thing.

    Though out of interest, how would adding a base href change the response for api/ping? Is flutter run reading the base href and behaving differently?

  9. mdebbar commented on Oct 7, 2020

    @mdebbar
    Contributor

    @DanTup yes, flutter run reads base href and only serves requests under that path. So if base href is /foo/bar/ and you send a request to /api/ping/ the server returns a 404.

  10. DanTup commented on Oct 8, 2020

    @DanTup
    ContributorAuthor

    Ah, good to know! I think the current workaround is probably simpler for now, but that might be an idea if we end up with other issues (or need more than just the api/ping to work that way). Thanks!

  11. changed the title [-]"flutter run -d chrome" dev server responds with 200 status/homepage HTML for missing files[/-] [+]Only serve index.html for path patterns known to match route paths[/+] on Jan 27, 2022
  12. added
    P3Issues that are less important to the Flutter project
    c: new featureNothing broken; request for a new capability
    on Jan 27, 2022
  13. yjbanov commented on Jan 27, 2022

    @yjbanov
    Contributor

    Reclassifying this as a feature request to support matching on path patterns that are valid route paths and only serving index.html to them. We already do some basic filtering of HTTP requests, but giving the developer more control would help even more.

  14. kevmoo commented on May 29, 2025

    @kevmoo
    Contributor

    Here's my vote here. I honestly think we should let folks opt-in to the "serve index file everywhere else" model. 404s are USEFUL!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: new featureNothing broken; request for a new capabilityplatform-webWeb applications specificallyteam-webOwned by Web platform teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-webTriaged by Web platform team

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions