Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore httpd plugin and update the Httpd class to use getURL #3805

Closed
colossatr0n opened this issue Oct 11, 2021 · 1 comment
Closed

Restore httpd plugin and update the Httpd class to use getURL #3805

colossatr0n opened this issue Oct 11, 2021 · 1 comment

Comments

@colossatr0n
Copy link

colossatr0n commented Oct 11, 2021

I'm submitting a ...
[x] bug report
[] feature request
[ ] support request

Current behavior:
Using the @ionic-native/httpd wrapper and cordova-httpd results in this error message:

Native: tried calling Httpd.startServer, but the Httpd plugin is not installed.
[ng] [console.warn]: Install the Httpd plugin: ‘ionic cordova plugin add cordova-plugin-httpd’

even though the plugin is installed and exists on the window object.

The @ionic-native/httpd class uses getUrl but cordova-httpd uses getURL (capitalization differences).

The reason it says it’s not installed is because Ionic checks if the window object contains the plugin, which passes, and then it does an additional check to see if the called methodName exists on the plugin object, which fails.

That logic can be found here:

if (!pluginInstance || (!!methodName && typeof pluginInstance[methodName] === 'undefined')) {

It looks like the method name has always been getURL on the cordova-httpd plugin repo, so the only way the plugin works with the native wrapper is if getUrl is never used.

Expected behavior:
Plugin wrapper httpd class should match the method name of the plugin. This will allow the httpd plugin to start up without throwing a warning that says it's not installed.

Steps to reproduce:
Install wrapper and httpd plugin as described here.
Follow the Angular setup as described in the previous link but call this.httpd.getUrl() instead of startServer().
Check the logs and there will be an error about the plugin not being installed.

Other information:
To fix this, the httpd wrapper will have to be restored to this repo as it was removed in this commit.
The issue can be fixed by updating the plugin wrapper httpd class to use getURL instead of getUrl.

I've submitted a PR to the cordova-httpd repo to add support for capacitor builds. It also includes a temporary fix to allow usage of both getUrl and getURL until this PR fixes its usage. See floatinghotpot/cordova-httpd#79.

If the cordova-httpd repo doesn't merge the changes, those changes can be found on the ionic-native-capacitor-compatability branch.

Also, if the httpd plugin was removed because of incompatibility, I was able to get it working by patching a portion of cordova-httpd. I've filed an issue with the cordova-http repo to actually implement a fix for it. For the most part though, it looks like the repo is no longer maintained.

Ionic info:

Ionic:

   Ionic CLI                     : 6.17.1 (/usr/local/lib/node_modules/@ionic/cli)
   Ionic Framework               : @ionic/angular 5.8.3
   @angular-devkit/build-angular : 12.1.4
   @angular-devkit/schematics    : 12.1.4
   @angular/cli                  : 12.1.4
   @ionic/angular-toolkit        : 4.0.0

Capacitor:

   Capacitor CLI      : 3.2.4
   @capacitor/android : not installed
   @capacitor/core    : 3.2.4
   @capacitor/ios     : 3.2.4

Utility:

   cordova-res : 0.15.3
   native-run  : 1.4.1

System:

   NodeJS : v14.17.6 (/usr/local/bin/node)
   npm    : 6.14.15
   OS     : macOS Catalina

@colossatr0n colossatr0n changed the title Restore httpd plugin and update interface Restore httpd plugin and update interface for getUrl Oct 11, 2021
@colossatr0n colossatr0n changed the title Restore httpd plugin and update interface for getUrl Restore httpd plugin and update the Httpd interface for getUrl Oct 11, 2021
@colossatr0n colossatr0n changed the title Restore httpd plugin and update the Httpd interface for getUrl Restore httpd plugin and update the Httpd class to use getURL Oct 11, 2021
colossatr0n added a commit to colossatr0n/cordova-capacitor-httpd that referenced this issue Oct 13, 2021
`getUrl`. Their declaration is for `getURL`. This commit adds
compatibility for both methods and can be reverted once the following
case has a fix:
danielsogl/awesome-cordova-plugins#3805
@github-actions
Copy link

There has been no recent activity and this issue has been marked inactive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant