Skip to content

A simple webserver plugin for Cordova / PhoneGap on Android using NanoHTTPD

License

MIT, BSD-3-Clause licenses found

Licenses found

MIT
LICENSE
BSD-3-Clause
NanoHTTPD_LICENSE.md
Notifications You must be signed in to change notification settings

alexandrelaplante/org.apache.cordova.plugin.webserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

org.apache.cordova.plugin.webserver

A simple webserver plugin for Cordova / PhoneGap on Android using NanoHTTPD.

Installation

cordova plugin add https://github.com/alexandrelaplante/org.apache.cordova.plugin.webserver.git

Add the following permissions to AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Usage

// Start the server
window.plugins.webserver.start(callback, [{'port' : 8080}]);

function callback (request) {

    if (request.constructor == String){
        // The first thing sent to the callback is the connection address.

        alert("direct your browser to " + request);

    } else {
        // All further calls are http requests.

        var response = [{
            'status' : 200,
            'mimetype' : 'text/html',
            'data' : '<html><head></head><body>'+ JSON.stringify(request) +'</body></html>'
        }];

        // Send a response to this request
        window.plugins.webserver.respond(response);
    }
}

// Stop the server
window.plugins.webserver.stop();

About

A simple webserver plugin for Cordova / PhoneGap on Android using NanoHTTPD

Resources

License

MIT, BSD-3-Clause licenses found

Licenses found

MIT
LICENSE
BSD-3-Clause
NanoHTTPD_LICENSE.md

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published