ionic-team / capacitor

Build cross-platform Native Progressive Web Apps for iOS, Android, and the Web āš”ļø
https://capacitorjs.com
MIT License
12.29k stars 1.01k forks source link

[Bug]: Hardcoded HTTP protocol for LiveReload prevents using HTTPS #7745

Closed MirazMac closed 2 weeks ago

MirazMac commented 3 weeks ago

Capacitor Version

 Capacitor Doctor

Latest Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

Installed Dependencies:

  @capacitor/ios: not installed
  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2

[success] Android looking great! šŸ‘Œ

Other API Details

npm --version
10.9.0

node --version
v22.11.0

Platforms Affected

Current Behavior

Despite setting an HTTPS URL in capacitor.config.ts, when ionic capacitor run android --livereload --external is run, the app loads the HTTP version of the URL.

import type { CapacitorConfig } from '@capacitor/cli';

const config: CapacitorConfig = {
  appId: 'io.ionic.starter',
  appName: 'LivSports',
  webDir: 'dist',
  server: {
    androidScheme: "https",
    url: "https://192.168.1.5:8100",
  }
};

export default config;

Upon inspecting the generated android\app\src\main\assets\capacitor.config.json file, it also shows that is it has removed the HTTPS from the URL and is using the HTTP instead.

{
    "appId": "io.ionic.starter",
    "appName": "LivSports",
    "webDir": "dist",
    "server": {
        "androidScheme": "https",
        "url": "http://192.168.1.5:8100"
    }
}

However, once the dev server exits this file changes the URL to https:// again.

It seems http is being hardcoded here: https://github.com/ionic-team/capacitor/blob/e4b05405a1319ca29fa328c584bba63bf5d281bb/cli/src/util/livereload.ts#L164

Expected Behavior

Ionic should use the server URL set in the config AS-IS. Stripping the protocol and using http by default defeats the purpose of setting an custom server URL entirely.

Project Reproduction

https://github.com/ionic-team/starters

Additional Information

My dev server is properly configured to use SSL, I generated the certificates and keys and added everything to the trust root and the live-server URL is accessible without any warnings in my phone via Chrome.

jcesarmobile commented 2 weeks ago

You are using ionic command to run the app, when using ionic command to run the app, the Capacitor livereload code is not used. You should be able to use https with ionic command by adding --ssl option.

androidScheme is not used for the live reload url, just for the url used for loading local assets.