Git Product home page Git Product logo

connect-phonegap's Introduction

connect-phonegap Build Status bitHound Score

Connect middleware to serve a PhoneGap app.

Examples

Standalone

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

Express

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

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

Connect

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

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

HTTP

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

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

API

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

phonegap()

Options:

  • [options] {Object}
  • [autoreload] {Boolean} toggle AutoReload watch (default: true).
  • [localtunnel] {Boolean} toggle localtunnel (default: false).

Events:

  • error is emitted when an error occurs.
  • log is emitted with log info.

Return:

  • {Function} request listener that can be provided to http.Server or used as connect middleware.

Example:

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

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

phonegap.listen(options, [callback])

phonegap.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:

  • [options]
    • [port] {Number} to listen on (Default: 3000).
    • all options available to phonegap() middleware.

Events:

  • complete is triggered when server starts. - data {Object}
    • server {http.Server} is the server running.
    • address {String} is the server address.
    • port {Number} is the server port.
  • error trigger when there is an error with the server or request.
    • e {Error} is null unless there is an error.
  • all events available to phonegap() middleware.
  • all events available to http.Server

Return:

  • {http.Server} instance that is also an event emitter.

Example:

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

phonegap.create(options)

The project is created from the same app template used by the PhoneGap CLI and Cordova CLI. When a template does not exist, it is fetched and saved in the common directory:

~/.cordova/lib/www/phonegap/VERSION/

Options:

  • options {Object}
    • path {String} is the path to create the project.
    • version {String} defines the PhoneGap app version.

Events:

  • progress emits state while downloading the app template.
    • state {Object} with received, total, and percentage.
  • error emitted when an error occurs.
    • e {Error}
  • complete emits when the project has been created.
    • data {Object} is indentical to the input options.

Example:

phonegap.create({
    path: 'path/to/app',
    version: '3.3.0'
})
.on('progress', function(state) {
    // only emitted when downloading a template.
    // state values are only defined when response supports
    // content-length header.
    if (state.percentage) {
        console.log('downloaded: ' + state.percentage + '%');
    }
})
.on('error', function(e) {
    // handle error
    console.log('error:', e);
})
.on('complete', function(data) {
    // data.path is the app path
    console.log('created project at: ' + data.path);
});

connect-phonegap's People

Contributors

mwbrooks avatar timkim avatar surajpindoria avatar purplecabbage avatar hermwong avatar lorinbeer avatar mrbr avatar doctorrustynelson avatar eliotsykes avatar globegitter avatar killfill avatar ylecuyer avatar marob avatar

Watchers

 avatar

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.