feat(cli): Add --https option for --live-reload#8194
feat(cli): Add --https option for --live-reload#8194OS-pedrogustavobilro merged 10 commits intoionic-team:mainfrom
Conversation
Enabling HTTPS could mislead to indicate that the cli would handle certificate management, which it won't.
|
Hey @Shellishack thanks for opening the PR! Tested here with ngrok and in conjunction with #7528 (otherwise |
|
Thanks @OS-pedrogustavobilro for your help! Loved the work Capacitor team has put up for this!! |
jcesarmobile
left a comment
There was a problem hiding this comment.
It should not add a default 443 port for https, in fact we shouldn't add 3000 port as default when not using https neither (but changing it right now would be a breaking change, so better leave 3000 as it is for now for non https urls)
If I use capacitor run ios --host 78d8-83-53-7-217.ngrok-free.app -l --https, since it adds the 443 port the url to load will be https://78d8-83-53-7-217.ngrok-free.app:443, but since it's the default port the WebView will turn the url into just https://78d8-83-53-7-217.ngrok-free.app, and since it doesn't match the url in the capacitor.config.json file it will open in Safari instead of inside the app.
|
@jcesarmobile good point, when I was testing I had that same issue in iOS, and had added the ngrok domain to capacitor config Thank you! |
Added a --https flag to allow
cap runto use https instead of http.[Edit by @OS-pedrogustavobilro] Fixes #8049. Partially addresses #8303
For example, now running with --https flag, cap cli will have:
Live reload remote
It works out of the box.
e.g.
cap run android -l --host=capacitorjs.com --https --port=443Live reload local https server
Using --https may cause capacitorjs not to load the content in WebView if the web view has a self-signed SSL certificate.
My local workaround (fully local, but make your own CA):
For local development, I ended up working around this by making a local CA certificate, and sign server certificates with this CA. Then I would need to install the CA file on my android device. Now live reloading a https local dev server is possible.
For nextjs:
If you have run
next dev --experimental-httpsbefore, delete ./certificates folder. Then continue.Do the below in
./certificatesfolderUse devCA.key to install on device later.
openssl genrsa -out devCA.key 2048 openssl req -x509 -new -nodes -key devCA.key -sha256 -days 3650 -out devCA.crt -subj "/CN=Local Development CA"e.g.
devCA.crton Android.First, copy
devCA.crtfrom PC to you android device. On Android, go to "settings -> security and privacy -> more security settings -> install from device storage -> CA certificate", then locatedevCA.crtand install.Now you can go back to root folder. Run
next dev --experimental-https, and runcap run android -l --host=mypc --https. Finally you should be able to see your local https server.Other options
Maybe try Ngrok (untested)