GithubHelp home page GithubHelp logo

apache / cordova-serve Goto Github PK

View Code? Open in Web Editor NEW
21.0 16.0 31.0 675 KB

Apache Cordova Serve Library

Home Page: https://cordova.apache.org/

License: Apache License 2.0

JavaScript 100.00%
cordova nodejs javascript mobile hacktoberfest

cordova-serve's Introduction

cordova-serve

NPM

Node CI

This module provides a JavaScript API to serve up a Cordova application in the browser.

API Example:

const cordovaServe = require('cordova-serve')();

cordovaServe.launchServer(options);
cordovaServe.servePlatform(platform, options);
cordovaServe.launchBrowser(options);

API Methods

launchServer()

Launches a local HTTP server.

Code Example:

const cordovaServe = require('cordova-serve')();

cordovaServe.launchServer(options).then(function () {
    const { server, port, root } = cordovaServe;
    ...
}, error => {
    console.log(`An error occurred: ${error}`);
});

Parameters:

  • options: described below in the following section "launchServer & servePlatform Options".

Return:

Returns a resolved or rejected promise depending on if the server had launched successfully.

On a fulfilled promise, the following properties are available on the returned object:

Property Description
serve The Node http.Server instance.
root The root that was specified, or cwd if none specified.
port The port that was used. (Either the requested port, the default port of 8000, or the incremented value of the chosen port when the chosen port is already in use).

servePlatform()

Launches a server that serves up any Cordova platform (e.g. browser, android, etc) from the current project.

Code Example:

const cordovaServe = require('cordova-serve')();

cordovaServe.servePlatform(platform, options).then(() => {
    const { server, port, projectRoot, root } = cordovaServe;
    ...
}, error => {
    console.log(`An error occurred: ${error}`);
});

Parameters:

  • options: described below in the following section "launchServer & servePlatform Options".

Return:

Note that for servePlatform(), the root value should be a Cordova project's root folder or any folder within it. servePlatform() will replace it with the platform's www_dir folder. If this value is not specified, the cwd will be used.

Returns a resolved or rejected promise depending on if the server had launched successfully.

On a fulfilled promise, the following properties are available on the returned object:

Property Description
serve The Node http.Server instance.
root The requested platform's www folder.
projectRoot The root folder of the Cordova project.
port The used port. requested port, the default port 8000, or incremented value of the chosen port when already in use).

launchBrowser()

Launches a browser window pointing to the specified URL.

Code Example:

const cordovaServe = require('cordova-serve')();

cordovaServe.launchBrowser(options).then(
  stdout => {
    console.log(`Browser was launched successfully: ${stdout}`);
  },
  error => {
    console.log(`An error occurred: ${error}`);
  }
);

Parameters:

  • options (optional):
Options Description
url The URL to open in the browser.
target The browser identifier to launch. Valid identifier: chrome, chromium, firefox, ie, opera, safari. (Default: chrome.)

Return:

Returns a resolved or rejected promise depending on if the browser had launched successfully.

launchServer & servePlatform Options

The options object passed to launchServer() and servePlatform() supports the following values (all optional):

Options Description
root The file path on the local file system that is used as the root for the server, for default mapping of URL path to the local file system path.
port The port for the server. Note that if this port is already in use, it will be incremented until a free port is found.
router An ExpressJS router. If provided, this will be attached before default static handling.
noLogOutput If true, all log output will be turned off.
noServerInfo If true, the Static file server running on... message will not be outputed.
events An EventEmitter to use for logging. If provided, logging will be output using events.emit('log', msg). If not provided, console.log() will be used. Note that nothing will be output in either case if noLogOutput is true.

cordova-serve's People

Contributors

audreyso avatar dpogue avatar erisu avatar gfzoli avatar janpio avatar jcesarmobile avatar niklasmerz avatar oliversalzburg avatar purplecabbage avatar raphinesse avatar ruslan-bikkinin avatar seamlink-aalves avatar sound120 avatar stevengill avatar zeprone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-serve's Issues

Optionally serve over HTTPS

Feature Request

Motivation Behind Feature

In some development environments, an API is served over SSL via the protocol https. Communicating with that API from a Cordova browser instance on a developer's machine is very efficient work flow. However, modern browsers disallow cross-origin communications between insecure and secured servers. In this case, the secured server is the API, and the insecure server is the current cordova-browser instance served with Node's http module. This is because it is always served without SSL.

Feature Description

The parent issue is in the cordova-browser repo with a full description, partially reproduced in this ticket: apache/cordova-browser#122

Alternatives or Workarounds

Exposing the API over non-secure http is an alternative. In my context, this was rejected strongly for security reasons, especially relating to corporate security accountability programs.

The second is that a developer independently hacks their local cordova installation to enable https. This is suboptimal since upgrading becomes a hassle, requiring careful VCS audits to restore erased, custom code.

Suspected Vulnerability & Bug Bounty - External Code Execution - huntr.dev

This issue has been generated on-behalf of Mik317 (https://huntr.dev/app/users/Mik317)

Overview

cordova-serve provides a JavaScript API to serve up a Cordova application in the browser.

The issue occurs because a user input is formatted inside a command that will be executed without any check.

Bug Bounty

We have opened up a bounty for this issue on our bug bounty platform. Want to solve this vulnerability and get rewarded ๐Ÿ’ฐ? Go to https://huntr.dev/

We will submit a pull request directly to your repository with the fix as soon as possible. Want to learn more? Go to https://github.com/418sec/huntr ๐Ÿ“š

Automatically generated by @huntr-helper...

forward the CLI user arguments to cordova-serve/browser

Feature Request

Motivation Behind Feature

I'm trying to pass --allow-file-access-from-files --disable-web-security to chromium, and it seems that cordova-serve/src/browser and callers are dropping the command line arguments.

Where should I forward this feature request? Thanks!

Feature Description

Forward the CLI user arguments to cordova-serve/src/browser from cordova-browser:

return server.launchBrowser({
    target: args.target,
    url: projectUrl,
    userArgs: args.remain
});

Then pass these arguments to the browser during launch in cordova-serve/src/browser

module.exports = function (opts) {
    var userArgs = opts.userArgs || '';
     /* ... */

function getBrowser (target, dataDir, userArgs) {
    /* ... */
}

Alternatives or Workarounds

Launch chrome manually and let the default instance handle local host launching

synchronize files with the local server

Feature Request

just like in other framework like ionic or angular the files are synchronized with the local server when testing

its very annoying to type every time you make changes cordova run browser it will be much easier if the files inside the www folder are synchronized with the browser.

to solve this issue I create this python script https://github.com/aymenBox/cordova-sync-browser/tree/main

which detect any changes in any file inside the www folder than stop the current server and start another one fill free to use it any one

Create new version

Hi, it would be quite helpfull if you could create a new version after merging #44.

Everytime VSCode cordova tools gets updated I get the same error because there is no version update cordova-serve and I can no longer debug the App.

Add support for remote development

Feature Request

Motivation Behind Feature

I'm using an iPad Pro as a terminal connected to a host development server and I need to access the werver remotely.

Feature Description

Add the option --host so we can run cordova run browser --host 0.0.0.0.

Alternatives or Workarounds

One can setup a web server to forward requests to localhost:8000

Error when trying to simulate with cordova-android 10

Bug Report

Problem

Cannot simulate Android in browser. I get error Error: Project does not include the specified platform: android although it's added

What is expected to happen?

Launch browser with app

What does actually happen?

I get error Error: Project does not include the specified platform: android

Information

util.js file that calls Api class from each platform with no parameters (line 82). In cordova-android the root definition was changed from this.root = path.resolve(__dirname, '..'); (v.9.1.0) to this.root = platformRootDir; (v.10).

When trying to set the app main path (line 66) const appMain = path.join(this.root, 'app', 'src', 'main'); because the first parameter is undefined.

To make it work I have to change line 82 and 83 of util.js to:

const platformRootFolder = path.join(cordovaProjectRoot, 'platforms', platformName);
const Api = require(path.join(platformRootFolder, 'cordova/Api'));
return new Api(platformName, platformRootFolder).locations.www;

Environment, Platform, Device

Cordova: 10.0.0
Cordova-android: 10.0.1
SO: Windows 10 PRO

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

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.