plus_plugins icon indicating copy to clipboard operation
plus_plugins copied to clipboard

[package_info_plus][web] can not load version.json when URI path contains index.html

Open kolotum opened this issue 2 years ago • 2 comments

Our Flutter web app is embedded in iframe of an external web platform using some URI pattern like https://external-domain.com/index.html. Because the path contains index.html package_info_plus_web fails to load version information from version.json.

System info

Platform the Issue occurs on: web Plugin name: package_info_plus_web Plugin version: 1.0.5

Steps to Reproduce

Create a local Flutter app with a sample page which is available as http://127.0.0.1:8081/#/my-sample-page

The same page should be available when we modify the path like

http://127.0.0.1:8081/index.html#/my-sample-page

Using the second URI the path in versionJsonUrl is wrong so the method fails to load version.json

In our case it would be sufficient to just remove the special case of index.html from the path in versionJsonUrl, e.g.:

  /// Get version.json full url.
  Uri versionJsonUrl(String baseUrl, int cacheBuster) {
    final baseUri = Uri.parse(baseUrl);
    final originPath =
        '${baseUri.origin}${baseUri.path.replaceAll('index.html', '')}';
    final versionJson = 'version.json?cachebuster=$cacheBuster';
    return Uri.parse(originPath.endsWith('/')
        ? '$originPath$versionJson'
        : '$originPath/$versionJson');
  }

But maybe this issue needs a more general solution?

kolotum avatar May 03 '22 21:05 kolotum

I have similar problem. Package is working on local host but return empty in release. (event without any index.html). I had to load version.json manually.

P-B1101 avatar Jun 13 '22 09:06 P-B1101

Same issue, version.json does not load. Not in debug localhost, or on release server.

SunlightBro avatar Jul 11 '22 10:07 SunlightBro

I have similar problem. Package is working on local host but return empty in release. (event without any index.html). I had to load version.json manually.

What do you mean by "load version.json manually"? How did you do that?

sebastianbuechler avatar Sep 22 '22 16:09 sebastianbuechler

When you build your web app, there will be a file named version.json and you can call it as an API directly. the URL will be something like you.domain.com/version.json it will return a JSON file that contains version name and version number.

but as I tested this on two servers, the first one returns an HTML page so you cant use it as a JSON response and encoded it. on the other hand, the second servers return a JSON response.

by the way, this package on the web is also called this URL to get the info, and when it tries to decode the response an exception will throw, so it returns an empty response. for the final solution, I have a static version number and version name and have a TODO on it so every time I am going to update the version I update this static too. and where I want to get this info at first try to load the JSON file and if it throws an exception I return this static as the response.

P-B1101 avatar Sep 23 '22 06:09 P-B1101

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 15 days

github-actions[bot] avatar Dec 28 '22 00:12 github-actions[bot]