phonegap / connect-phonegap

Stream a PhoneGap app to any device.
Apache License 2.0
61 stars 63 forks source link

connect-phonegap

Build Status codecov

Connect middleware to serve a PhoneGap app.

What is it?

A fine question for an even finer middleware. connect-phonegap is a server that runs on your development machine (typically through the phonegap-cli) and serves your PhoneGap app to the accompanying PhoneGap Developer App. connect-phonegap does this by watching your PhoneGap project and first sends a zip of the www/ to your app. When you update your project, the differences are then sent to your connected phone to display updates.

To note: when the server sends content to your phone, the server is also injecting js inline into the .html pages. The injected scripts are for detecting changes on the server, logging, handling three/four finger taps, etc. Sometimes this may interfere with your own js code that you may write. Therefore, we have options in order to toggle these scripts.

Examples

Standalone

var pgConnect = require('connect-phonegap');
pgConnect.listen();

Express

var pgConnect = require('connect-phonegap'),
    express = require('express'),
    app = express();

app.use(pgConnect());
app.listen(3000);

Connect

var pgConnect = require('connect-phonegap'),
    connect = require('connect'),
    app = connect();

app.use(pgConnect());
app.listen(3000);

HTTP

var pgConnect = require('connect-phonegap'),
    http = require('http');

var server = http.createServer(pgConnect());
server.listen(3000);

API

var pgConnect = require('connect-phonegap');

pgConnect()

Options:

Events:

Return:

Example:

var pgConnect = require('connect-phonegap')(),
    middleware = pgConnect();

// subscribe to events
middleware.on('log', function() {
    console.log.apply(this, arguments);
});

// use as middleware
app.use(middleware);

// or

// use as request listener
http.createServer(middleware).listen(3000);

pgConnect.listen(options, [callback])

pgConnect.serve(options, [callback])

Creates a local server to serve up the project. The intended receiver is the PhoneGap App but any browser can consume the content.

Options:

Events:

Return:

Example:

pgConnect.listen()
        .on('complete', function(data) {
            // server is now running
        })
        .on('error', function(e) {
            // an error occured
        });
});