-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
Capacitor Version: 8.0.0
Thanks Ionic team for the work you do! The root issue that I'm calling out with this issue is that cap run -l ignores server config, but there are a few related issues imo worth solving here. I'm hoping that this issue can be a suitable place to discuss them at a high level before creating small-scope issues.
If preferred, I'm happy to break these out into small-scope tickets now, just lmk.
Current Behavior
cap run -l ignores capacitor.config.{ts|json|etc} server config. Instead, what happens is as follows:
- If
--hostcli arg is used, use that value- If not, resolve to a reasonable external network interface || localhost
- If
--portcli arg is used, use that value- Otherwise, use port 3000
- Concatenate values to form connection string
http://{host}:{port}
Pain points, use cases, solutions
Hardcoded http protocol
Paint point 1: My company's auth provider refuses to work on non-localhost && non-encrypted (http://) connections. I.e. http://localhost is fine, but http://192.168.x.x fails. This of course creates problems for running locally on hardware devices.
Pain point 2: I would like to add tunneling to my app via a --tunnel flag. A standard tunneling setup might use ngrok, and would therefore use a connection string like https://some-endpoint.ngrok.com. In order to do this, I would need to pass that endpoint to cap run -l at runtime. Using just --host and --port this is impossible; I need to be able to control the protocol.
Solutions: Add support for a --https/--protocol/ssl flag to cap run -l.
Bad values imputed when no host/port
Pain point 1: cap run -l auto selects a reasonable network interface to try to load the app from. Oftentimes, a non-peer-accessible network is selected. I regularly experience this behavior:
- I'm at a coffee shop/on a mobile hotspot which blocks peer traffic on e.g. the 10.x.x.x address space
- 169.254.x.x address space is peer-accessible
Pain point 2: cap run -l uses port 3000 when a --port cli arg isn't passed. We cannot reasonably make the assumption that we should use port 3000, especially when one of the dominant bundlers uses 5173 by default.
Solutions: Three distinct behaviors here would constitute a solution:
- If
--hostand--portare unset, useserver.url- If
server.urlis unset, use reasonable default according to existing strategy
- If
- If
--hostis unset, useserver.hostnamefor host - Add
portto server config- if
--portis unset, useserver.port - If
server.portis unset, use reasonable default according to existing strategy
- if
Remaining server fields are ignored
I haven't experienced pain points with fields iosScheme, androidScheme, errorPath, appStartPath, clearText. I have however with allowNavigation.
Pain point: As mentioned in the section on http protocol hardcoding, I would like to set up tunneling. In order to do this, I need to add ngrok endpoints to allowNavigation. This is impossible with cap run -l because these config fields get nuked.
Docs Mismatch
I believe that the fixes I've articulated here would make this experience in line with what users expect; it works this way when running via Xcode, why wouldn't it work this way via cap run -l? In addition, the docs for Capacitor configuration and cap run make no mention of these limitations.
Action Items
I'm happy to open PRs to address each fix individually in the proposed order:
- When
--hostand--portare unset, usecapacitor.config.*serverconfig values. Addportsupport toserverconfig object here too. If all values unset, use existing strategy for reasonable defaults - Preserve
serverconfig items when usingcap run -l - Add
--httpssupport to `cap run
Would Ionic welcome PRs to address any of these problems? If so, I will happy open PRs to address whatever work is welcome. In my experience, they would go a long way in reconciling observed behavior with documented behavior, and bettering the DX.
Thanks again for the work you do.
Other API Details
Platforms Affected
- iOS
- Android
- Web
Current Behavior
cap run -l ignores capacitor.config.{ts|json|etc} server config. Instead, what happens is as follows:
- If
--hostcli arg is used, use that value- If not, resolve to a reasonable external network interface || localhost
- If
--portcli arg is used, use that value- Otherwise, use port 3000
- Concatenate values to form connection string
http://{host}:{port}
Expected Behavior
cap run -l respects server config object in capacitor.config.*
Project Reproduction
https://github.com/aolsenjazz/fresh-cap-repo
Additional Information
File references: