jh3141 / cordova-plugin-httpserver-dynamic

A plugin for Apache Cordova that runs a web server that is able to serve dynamic content.
5 stars 2 forks source link

Any way to stop the server or otherwise make it not crash on a page reload? #4

Open BodoMinea opened 3 years ago

BodoMinea commented 3 years ago

Hi,

At some points in my app's execution, the page may be refreshed, causing the code to be re-run. This causes the plugin to loose connection with the underlying Java server and thus the cordova side of the server is not working anymore.

One solution would be to stop the server before refresh, so that when the pages reinitializes everything is „fresh”.

I see there was an attempt to make a „stop” function but it is not finished and commented out: https://github.com/jh3141/cordova-plugin-httpserver-dynamic/blob/master/plugin/www/dynamicHttpServer.js#L34

My knowledge of Java is limited and the project seems abandoned so I am addressing the potential community - does anyone know how to make the stop function work?

Thanks.

BodoMinea commented 2 years ago

I implemented the server stop function in my own fork - https://github.com/BodoMinea/cordova-plugin-httpserver-dynamic The command is cordova.plugins.dynamicHttpServer.stopServer(serverId, successCallback, errorCallback); Install with cordova plugin add 'https://gitpkg.now.sh/BodoMinea/cordova-plugin-httpserver-dynamic/plugin?master' or clone and install locally.