Skip to content

Commit

Permalink
fix(android): allow fetch to local files on livereload (#2067)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Oct 18, 2019
1 parent 219c885 commit ccc00b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions android/capacitor/src/main/java/com/getcapacitor/Bridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,16 @@ private void loadWebView() {
authorities.add(appUrlObject.getAuthority());
} catch (Exception ex) {
}

localUrl = appUrlConfig;
appUrl = appUrlConfig;
if (BuildConfig.DEBUG) {
Toast.show(getContext(), "Using app server " + appUrlConfig.toString());
Toast.show(getContext(), "Using app server " + appUrlConfig);
}
} else {
appUrl = localUrl;
// custom URL schemes requires path ending with /
if (!scheme.equals(Bridge.CAPACITOR_HTTP_SCHEME) && !scheme.equals(CAPACITOR_HTTPS_SCHEME)) {
appUrl += "/";
}
}

Expand All @@ -203,16 +210,6 @@ private void loadWebView() {
localServer = new WebViewLocalServer(context, this, getJSInjector(), authorities, html5mode);
localServer.hostAssets(DEFAULT_WEB_ASSET_DIR);

if (appUrlConfig == null) {
appUrl = localUrl;
// custom URL schemes requires path ending with /
if (!scheme.equals(Bridge.CAPACITOR_HTTP_SCHEME) && !scheme.equals(CAPACITOR_HTTPS_SCHEME)) {
appUrl += "/";
}
} else {
appUrl = appUrlConfig;
}

Log.d(LOG_TAG, "Loading app at " + appUrl);

webView.setWebChromeClient(new BridgeWebChromeClient(this));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public WebResourceResponse shouldInterceptRequest(WebResourceRequest request) {
return null;
}

if (isLocalFile(loadingUrl) || loadingUrl.toString().startsWith(bridge.getLocalUrl())) {
if (isLocalFile(loadingUrl) || Config.getString("server.url") == null) {
Log.d(LogUtils.getCoreTag(), "Handling local request: " + request.getUrl().toString());
return handleLocalRequest(request, handler);
} else {
Expand Down

0 comments on commit ccc00b3

Please sign in to comment.