Skip to content
This repository has been archived by the owner on Sep 25, 2018. It is now read-only.

Commit

Permalink
Improve ngrok error handling in exp/xde/xdl (#817)
Browse files Browse the repository at this point in the history
* Test ngrok tunnels and use a fallback if necessary

Before displaying a tunnel URL in XDE, check that it actually works.
If it doesn't, fall back to a LAN URL.

Note: there's some existing fallback behavior in
`UrlUtils.constructUrlAsync` (see: https://github.com/expo/universe/blob/cbbda0bdcc77795024537d1dcba584879b3ed056/dev/xdl/src/UrlUtils.js#L233-L240)
But because it doesn't test the URL, it's only triggered if the tunnel
was not created in the first place. We also can't easily detect when
this fallback happens. That's why an explicit test and fallback is
necessary.

* Use `/status` endpoint to check if packager is alive

This is less hacky than searching for the string "Cached Bundles" in
the `/debug` endpoint output and less likely to break in the future
since it's the mechanism react-native itself uses to check if the
packager is running.

* Upgrade @expo/ngrok to v2.2.9

* Add tunnel URL fallback and warning to exp

* Avoid testing tunnel URLs when in offline mode

fbshipit-source-id: 3c9d275
  • Loading branch information
fson authored and expbot committed Oct 16, 2017
1 parent 84a7dc7 commit b1ea4bc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dependencies": {
"@expo/bunyan": "^1.8.10",
"@expo/json-file": "^5.0.1",
"@expo/ngrok": "2.2.8",
"@expo/ngrok": "2.2.9",
"@exponent/electron-cookies": "^2.0.0",
"aphrodite": "^1.2.3",
"autobind-decorator": "^1.3.4",
Expand Down
18 changes: 15 additions & 3 deletions src/ui/MainScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1162,12 +1162,24 @@ class MainScreen extends React.Component {
}
}

async _computeUrlAsync(root) {
if (!root) {
async _computeUrlAsync(projectRoot) {
if (!projectRoot) {
return null;
}

return UrlUtils.constructManifestUrlAsync(root);
const {
url,
isUrlFallback,
} = await Project.getManifestUrlWithFallbackAsync(projectRoot);

if (isUrlFallback) {
this._logError(
'Switched to a LAN URL because the tunnel appears to be down. ' +
'Only devices in the same network can access the app. ' +
'You can restart the project to try reconnecting.'
);
}
return url;
}

_registerLogs() {
Expand Down

0 comments on commit b1ea4bc

Please sign in to comment.