All Projects → bykof → cordova-plugin-webserver

bykof / cordova-plugin-webserver

Licence: other
A webserver plugin for cordova

Programming Languages

java
68154 projects - #9 most used programming language
swift
15916 projects
javascript
184084 projects - #8 most used programming language
objective c
16641 projects - #2 most used programming language

Projects that are alternatives of or similar to cordova-plugin-webserver

Taisite Platform
最强接口测试平台
Stars: ✭ 203 (+100.99%)
Mutual labels:  backend, requests
Libhv
🔥 比libevent、libuv更易用的国产网络库。A c/c++ network library for developing TCP/UDP/SSL/HTTP/WebSocket client/server.
Stars: ✭ 3,355 (+3221.78%)
Mutual labels:  webserver, requests
Cordova Httpd
Embed tiny web server into Cordova with a plugin
Stars: ✭ 271 (+168.32%)
Mutual labels:  cordova, webserver
Hydra
后端一站式微服务框架,提供API、web、websocket,RPC、任务调度、消息消费服务器
Stars: ✭ 407 (+302.97%)
Mutual labels:  backend, webserver
larasar
Laravel + Quasar Framework
Stars: ✭ 77 (-23.76%)
Mutual labels:  cordova, backend
cordova-posprinter-sample
Cordova/Inoic sample for Epson ESC/POS printer
Stars: ✭ 24 (-76.24%)
Mutual labels:  cordova
MemoBoard
Flask and React based intranet app where you can create and share lists (e.g. shopping list, todo, ...)
Stars: ✭ 35 (-65.35%)
Mutual labels:  webserver
Pony
Haxe open-cross-library
Stars: ✭ 88 (-12.87%)
Mutual labels:  cordova
ionic-3-video-calling-using-webrtc
This is demo code of how to implement video calling in ionic 3 using webrtc
Stars: ✭ 58 (-42.57%)
Mutual labels:  cordova
net
A small, modern, PSR-7 compatible PSR-17 and PSR-18 network library for PHP, inspired by Go's net package.
Stars: ✭ 16 (-84.16%)
Mutual labels:  response
multi-projects-architecture-with-Ktor
A Ktor real world example built on multi-projects architecture
Stars: ✭ 29 (-71.29%)
Mutual labels:  backend
apiron
🍳 apiron is a Python package that helps you cook a tasty client for RESTful APIs. Just don't wash it with SOAP.
Stars: ✭ 106 (+4.95%)
Mutual labels:  requests
v-cupertino
A Vue 3 Wrapper for Cupertino Pane Library
Stars: ✭ 17 (-83.17%)
Mutual labels:  cordova
odufrn-downloader
Pacote para baixar os dados do portal de dados abertos da UFRN
Stars: ✭ 31 (-69.31%)
Mutual labels:  requests
cordova-discuss
Discussions on features and the future
Stars: ✭ 18 (-82.18%)
Mutual labels:  cordova
sisyphus
Sisyphus is the way how we provide backend services.
Stars: ✭ 59 (-41.58%)
Mutual labels:  backend
issue-wanted
🏷 Web application to help beginners to start contributing into Haskell projects
Stars: ✭ 61 (-39.6%)
Mutual labels:  backend
rust-web-boilerplate
An implementation of a simple web server using Rust
Stars: ✭ 36 (-64.36%)
Mutual labels:  webserver
get hired training
A set of videos and tips to help our students to be hired as developers 💯
Stars: ✭ 18 (-82.18%)
Mutual labels:  backend
fastapi-framework
A FastAPI Framework for things like Database, Redis, Logging, JWT Authentication, Rate Limits and Sessions
Stars: ✭ 26 (-74.26%)
Mutual labels:  backend

cordova-plugin-webserver

A webserver plugin for cordova

This plugin helps you to start a full webserver in JavaScript on Android and iOS.

Current supported platforms

  • Android (i think all versions?! Tell me if it's not true)
  • iOS (8.0 or later (armv7, armv7s or arm64))

Why?

I started this project because I wanted a solution like ExpressJS but hybrid (for iOS and Android). I didn't want to build two native applications which each serve a backend (two codebases are just bah!). So this is the solution to create a Webserver which can receives HTTP Requests and responds with HTTP Responds.

Installation

Just add the cordova plugin to your project

cordova plugin add https://github.com/bykof/cordova-plugin-webserver

Use

Ok so it's pretty ez. There are 4 Methods which are available in the webserver variable:

  • start(port) or start()
  • stop()
  • onRequest(request)
  • sendResponse(responseId, responseObject, callbackSuccess, callbackError)

start(port)

port (optional): Set a port of your webserver. Default port: 8080

This method will start your webserver.

stop()

This method will stop your webserver.

onRequest(callback(request))

Every time the webserver receives an request your callback function is called. The request params will look like this:

{
	requestId: '3jh4-ku34k-k3j4k-k3j42',
	body: '',
	headers: {
		... some headers
	},
	method: 'POST',
	path: '/hello/world',
	query: 'bla=wer&blu=2'
}

sendResponse(requestId, responseObject, callbackSuccess, callbackError)

If you received a request you will probably send a response "cough"... We need to add a requestId param to map a response to a request, because internally the webserver will wait for the response. (Yes currently the webserver will wait until there aren't computers anymore on earth).

The params have to look like this (there are not default values for the params!):

{
	status: 200,
	body: '<html>Hello ... something</html>',
	headers: {
		'Content-Type': 'text/html' <--- this is important
	}
}

Serving files

To serve a file in response to an http request you should use path param which points to the file location on the device.

{
	status: 200,
	path: '/sdcard0/Downloads/whatever.txt',
	headers: {
        }
}

The cordova-plugin-file plugin can be used to locate the path of the file data to be sent. For android you might need strip the file:// part of the file path for it to work.

window.resolveLocalFileSystemURL('cdvfile://localhost/temporary/path/to/file.mp4', function(entry) {
  console.log(entry.toURL());
});

Example

webserver.onRequest(
	function(request) {
		console.log("O MA GAWD! This is the request: ", request);

		webserver.sendResponse(
			request.requestId,
			{
				status: 200,
				body: '<html>Hello World</html>',
				headers: {
					'Content-Type': 'text/html'
				}
			}
		);
	}
);

webserver.start();

//... after a long long time
// stop the server
webserver.stop();

Credits

Special thanks to:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].