Giter VIP home page Giter VIP logo

org.apache.cordova.plugin.webserver's Introduction

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();

org.apache.cordova.plugin.webserver's People

Contributors

alexandrelaplante avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

org.apache.cordova.plugin.webserver's Issues

Serve BIN file on GET request

I'm looking for a way to serve a bin file (with sensitivity for changes) upon GET request, and read the callback once download was complete/successful.
I understand its not possible to serve file for download using this module (no root dir) but perhaps there is a cool way like in your example?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.