cordova-plugin-webserver
cordova-plugin-webserver copied to clipboard
plugin_not_installed on android
I want to use the WebServer in an Ionic4 app on android and IOS, build with angular.
I installed the plugin via
ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver
npm install --save @ionic-native/web-server
I importet WebService in app.module.ts in providers
import { WebServer } from '@ionic-native/web-server/ngx';
I want to create a service, with the following code:
`constructor(private myServer: WebServer, private networkFinder: NetworkFinderService, private platform: Platform) {
this.IP = networkFinder.clientInformation.IP;
this.platform.ready().then(() => {
this.myServer.onRequest().subscribe(request => {
const response = {
status: 200,
body: 'Working',
headers: {
'Content-Type': 'text/html'
}
};
console.log('Request: ', request);
this.myServer.sendResponse(request.requestId, response);
});
this.myServer.start(PORT)
.then(() => {
console.log('Start Webserver on ', this.IP, ':', PORT);
}).catch((error) => {
console.error(error);
});
});
}`
But i also tried this in app.component.ts in the constructor.
Then i build the android apk and run on the device via cordova.
Put i alwas get the error: plugin_not_installed.
Does anybody knows the solution?
Thanks for help
Hey did you found any solution for this problem? I'm in the same situation, thanks!
Best regards from Guatemala.
Thank for the response, that was exactly what I did, I just created a new project and I was able to load the plugin properly.
Hi @DaveMans .
How did you solve the issue? I have the same problem
Same problem here. Any update?
Hi @Maurocruzter and @Ovilia , I didn't check this until today, sorry :)
Well, basically what I did was that I created a complete new project, and then I installed the plugin from github repository, then I moved my code from the original project to the new one, is not an "elegant" solution but it worked for me, hope that helps!!
Regards!
:)
@DaveMans May I ask when did you do that? Maybe it's caused in a recent commit?
I tried it with an empty project but the same error occurs. Here's what I did:
ionic start ionicserver
cd ionicserver
ionic cordova plugin add cordova-plugin-webserver
ionic cordova platform add ios
npm install @ionic-native/web-server
ionic cordova build ios
The code is:
import {Component} from '@angular/core';
import {Platform} from '@ionic/angular';
import {WebServer, Response} from '@ionic-native/web-server/ngx';
@Component({
selector: 'app-home',
templateUrl: 'home.page.html',
styleUrls: ['home.page.scss'],
})
export class HomePage {
constructor(protected platform: Platform, protected webServer: WebServer) {
this.platform.ready().then(() => {
this.webServer.onRequest().subscribe(data => {
console.log(data);
const res: Response = {
status: 200,
body: '',
headers: {
'Content-Type': 'text/html'
}
};
this.webServer.sendResponse(data.requestId, res)
.catch((error: any) => console.error(error));
});
this.webServer.start(80)
.then(() => console.log('server started'))
.catch((error: any) => console.error(error));
});
}
}
Error message:
WARN: Native: tried calling WebServer.onRequest, but the WebServer plugin is not installed.
WARN: Install the WebServer plugin: 'ionic cordova plugin add cordova-plugin-webserver'
ERROR: plugin_not_installed
@Ovilia Although I have never used ionic myself, I believe ionic cordova plugin add cordova-plugin-webserver tries to install it from NPM. This plugin is not yet published to NPM. There is currently a package on NPM that is using the same name as this repo, but is actually something different (see https://github.com/bykof/cordova-plugin-webserver/issues/37). Try installing it through GitHub directly.
@boedy It worked for me! Thanks for saving my day! 😆
For others having the same problem here, try remove the one installed with npm and
ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver.git
@Ovilia Although I have never used ionic myself, I believe
ionic cordova plugin add cordova-plugin-webservertries to install it from NPM. This plugin is not yet published to NPM. There is currently a package on NPM that is using the same name as this repo, but is actually something different (see #37). Try installing it through GitHub directly.
Thank you very much!!