cordova-plugin-webserver

Cordova plugin for localhost web server written in Kotlin and Ktor

Install plugin

cordova plugin add https://github.com/Qbix/cordova-plugin-webserver.git

Supported platforms

Let’s start

  • First step: In your index.js file add this line to start the web server
cordova.plugins.webServer.startServer(function(result) { console.log(result); }, function(error) { console.log(error); })
  • Second step: Build and run your app. Voila, enjoy the web server!

Start Server

cordova.plugins.webServer.startServer(function(result) { console.log(result); }, function(error) { console.log(error); })

Stop Server

cordova.plugins.webServer.stopServer(function(result) { console.log(result); }, function(error) { console.log(error); })

Requests

Serving static content

GET request:

http://localhost:3005/static-content/{your path from assets directory}

Example with serving index.html:

http://localhost:3005/static-content/www/index.html

Executing Cordova methods

POST request:

curl -X POST -F service=CordovaServiceName -F action=CordovaMethod -F args=["Args"] http://localhost:3005/cordova-request

Example with common cordova request:

Q.Users.Cordova.Labels.get(["e"], function(data) { console.log(data); }, function(err) { console.log(err); })

equivalent to

curl -X POST -F service=QUsersCordova -F action=get -F args=[["e"]] http://localhost:3005/cordova-request

GitHub

View Github