2016-07-18 01:53:58 +08:00
|
|
|
import { Cordova, Plugin } from './plugin';
|
2016-09-10 03:45:24 +08:00
|
|
|
import { Observable } from '@reactivex/rxjs';
|
2016-07-18 01:53:58 +08:00
|
|
|
|
|
|
|
|
2016-06-11 12:33:02 +08:00
|
|
|
/**
|
|
|
|
* @name Httpd
|
|
|
|
* @description
|
|
|
|
* Embedded httpd for Cordova apps. Light weight HTTP server.
|
2016-06-11 14:34:08 +08:00
|
|
|
* @usage
|
2016-08-11 19:55:26 +08:00
|
|
|
* ```typescript
|
|
|
|
* import {Httpd, HttpdOptions} from 'ionic-native';
|
|
|
|
*
|
|
|
|
* let options: HttpdOptions = {
|
|
|
|
* www_root: 'httpd_root', // relative path to app's www directory
|
|
|
|
* port: 80,
|
|
|
|
* localhost_only: false
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* Httpd.startServer(options).subscribe((data) => {
|
|
|
|
* console.log('Server is live');
|
|
|
|
* });
|
|
|
|
*
|
|
|
|
* ```
|
2016-06-11 12:33:02 +08:00
|
|
|
*/
|
|
|
|
@Plugin({
|
2016-07-18 01:53:58 +08:00
|
|
|
plugin: 'https://github.com/floatinghotpot/cordova-httpd.git',
|
|
|
|
pluginRef: 'cordova.plugins.CorHttpd',
|
|
|
|
repo: 'https://github.com/floatinghotpot/cordova-httpd',
|
|
|
|
platforms: ['iOS', 'Android']
|
2016-06-11 12:33:02 +08:00
|
|
|
})
|
|
|
|
export class Httpd {
|
|
|
|
|
2016-07-18 01:53:58 +08:00
|
|
|
/**
|
|
|
|
* Starts a web server.
|
|
|
|
* @returns {Observable<string>} Returns an Observable. Subscribe to receive the URL for your web server (if succeeded). Unsubscribe to stop the server.
|
|
|
|
* @param options {HttpdOptions}
|
|
|
|
*/
|
|
|
|
@Cordova({
|
|
|
|
observable: true,
|
|
|
|
clearFunction: 'stopServer'
|
|
|
|
})
|
2016-08-11 19:55:26 +08:00
|
|
|
static startServer(options?: any): Observable<string> { return; }
|
2016-07-18 01:53:58 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the URL of the running server
|
|
|
|
* @returns {Promise<string>} Returns a promise that resolves with the URL of the web server.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getUrl(): Promise<string> { return; }
|
2016-06-11 12:33:02 +08:00
|
|
|
|
2016-07-18 01:53:58 +08:00
|
|
|
/**
|
|
|
|
* Get the local path of the running webserver
|
|
|
|
* @returns {Promise<string>} Returns a promise that resolves with the local path of the web server.
|
|
|
|
*/
|
|
|
|
@Cordova()
|
|
|
|
static getLocalPath(): Promise<string> { return; }
|
2016-06-11 12:33:02 +08:00
|
|
|
|
|
|
|
}
|
2016-07-18 01:53:58 +08:00
|
|
|
|
2016-06-11 12:33:02 +08:00
|
|
|
/**
|
|
|
|
* These options are used for the Httpd.startServer() function.
|
|
|
|
*/
|
|
|
|
export interface HttpdOptions {
|
2016-07-18 01:53:58 +08:00
|
|
|
/**
|
|
|
|
* The public root directory for your web server. This path is relative to your app's www directory.
|
|
|
|
* Default is current directory.
|
|
|
|
*/
|
|
|
|
www_root?: string;
|
|
|
|
/**
|
|
|
|
* The port number to use.
|
|
|
|
* Default is 8888
|
|
|
|
*/
|
|
|
|
port?: number;
|
|
|
|
/**
|
|
|
|
* Setting this option to false will allow remote access to your web server (over any IP).
|
|
|
|
* Default is false.
|
|
|
|
*/
|
|
|
|
localhost_only?: boolean;
|
|
|
|
}
|