Closed oenlighteno closed 6 years ago
Okay I have tried it now. Sorry for the long delay.
ionic start
and choosed "blank template".ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver
const webserver = window['plugins']['webserver'];
webserver.onRequest( function(request) { console.log("O MA GAWD! This is the request: ", request);
webserver.sendResponse(
request.requestId,
{
status: 200,
body: '<html>Hello World</html>',
headers: {
'Content-Type': 'text/html'
}
}
);
}
);
webserver.start();
The most important thing is `const webserver = window['plugins']['webserver'];`
Because ionic 2 is using typescript and you have to access the plugin over the window object.
Thank you for your tryed. Thank you so much Do you mean end of file, that mean outer class bracket?
เมื่อ 29 พ.ย. 2017 6:00 หลังเที่ยง "Michael Bykovski" < notifications@github.com> เขียนว่า
Okay I have tried it now. Sorry for the long delay.
- I started a new project with ionic start and choosed "blank template".
- Install the plugin: ionic cordova plugin add https://github.com/bykof/cordova-plugin-webserver https://github.com/bykof/cordova-plugin-webserver
- Open main.ts and type at the end of the file
webserver.onRequest( function(request) { console.log("O MA GAWD! This is the request: ", request);
webserver.sendResponse( request.requestId, { status: 200, body: '<html>Hello World</html>', headers: { 'Content-Type': 'text/html' } } );
} ); webserver.start(); //... after a long long time// stop the serverwebserver.stop();
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bykof/cordova-plugin-webserver/issues/4#issuecomment-347825993, or mute the thread https://github.com/notifications/unsubscribe-auth/AdL0CaMjYfUWPStxN19GNJNMw2lwFmndks5s7TlIgaJpZM4QZ0TR .
I mean, that you cant access webserver in typescript by default. You have to save it with this statement:
const webserver = window['plugins']['webserver'];
ok thank you.
2017-11-29 19:15 GMT+07:00 Michael Bykovski notifications@github.com:
I mean, that you cant access webserver in typescript by default. You have to save it with this statement:
const webserver = window['plugins']['webserver'];
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/bykof/cordova-plugin-webserver/issues/4#issuecomment-347843034, or mute the thread https://github.com/notifications/unsubscribe-auth/AdL0Cd_R0Kshq8d1fVTfNc5PhLZRGgYxks5s7Ur1gaJpZM4QZ0TR .
i get
Runtime Error
undefined is not an object (evaluating 'window['plugins']['webserver']')
when i am trying to access window['plugins']['webserver']
in main.ts
@NickStrupat i get the same error
@bykof please help me to solve this, i was confused many days. thank you
Have you tried this: https://stackoverflow.com/questions/45080622/ionic-how-to-access-a-cordova-plugin @waidp521 @NickStrupat
Hey @bykof @oenlighteno @NickStrupat , still it isn't working with ionic 2. I tried mostly everything, but nothing starts. I get some errors on inspecting it, saying that plugin isn't installed, but I correctly installed it with your repo and directly as well.
Please help.
When i test with pure cordova it work, but when i test with ionic cordova it not work. How to fix this?