You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Only serve index.html for path patterns known to match route paths #67053
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#/
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.
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.
@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?
@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.
@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?
@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.
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!
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
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.
Activity
Consider API responses to api/ping with text/html header as failures
jonahwilliams commentedon Oct 1, 2020
@mdebbar
Consider API responses to api/ping with text/html header as failures (#…
Vitor-Bukovitz commentedon Oct 1, 2020
Same here but I'm getting my website regardless of what comes after
/, e.g:https://www.mywebsite.com/12398ueushadihsa12iuAfter it loads the URL becomes like this:
https://www.mywebsite.com/12398ueushadihsa12iu#/mdebbar commentedon Oct 1, 2020
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 usePathUrlStrategy(instead of the oldHashUrlStrategy) you can visit:http://localhost:8080/profilewhich loads your app, and use/profileas a route name for the Navigator.That said, I would like to learn more if this is causing any issues for you.
DanTup commentedon Oct 5, 2020
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/pingand 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!
DanTup commentedon Oct 5, 2020
@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?
mdebbar commentedon Oct 7, 2020
@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 ofhttp://localhost:12345/)? You can do that by adding<base href="/devtools/">to theweb/index.htmlfile. If you do this, all requests that aren't prefixed with/devtools/will get a 404 response. So your/api/pingrequest will receive 404 response as you expect.Let me know if this workaround is okay for you.
DanTup commentedon Oct 7, 2020
@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 hrefchange the response for api/ping? Isflutter runreading thebase hrefand behaving differently?mdebbar commentedon Oct 7, 2020
@DanTup yes,
flutter runreadsbase hrefand 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.DanTup commentedon Oct 8, 2020
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!
[-]"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[/+]yjbanov commentedon Jan 27, 2022
Reclassifying this as a feature request to support matching on path patterns that are valid route paths and only serving
index.htmlto them. We already do some basic filtering of HTTP requests, but giving the developer more control would help even more.kevmoo commentedon May 29, 2025
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!
Fix Wasm build cache mismatch in ResidentWebRunner and browser 404 fa…