{"id":17521728,"url":"https://github.com/bykof/cordova-plugin-webserver","last_synced_at":"2025-04-09T15:04:09.373Z","repository":{"id":37735943,"uuid":"96524337","full_name":"bykof/cordova-plugin-webserver","owner":"bykof","description":"A webserver plugin for cordova","archived":false,"fork":false,"pushed_at":"2023-09-21T17:22:54.000Z","size":649,"stargazers_count":125,"open_issues_count":28,"forks_count":50,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-09T15:01:26.408Z","etag":null,"topics":["backend","cordova","http","plugin","requests","response","rest","webserver"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bykof.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-07T09:44:30.000Z","updated_at":"2025-03-12T16:06:24.000Z","dependencies_parsed_at":"2024-11-14T18:45:44.597Z","dependency_job_id":null,"html_url":"https://github.com/bykof/cordova-plugin-webserver","commit_stats":{"total_commits":64,"total_committers":10,"mean_commits":6.4,"dds":0.59375,"last_synced_commit":"53beb743bcaffb815d9eb754fb7b4ce50f6d428c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bykof%2Fcordova-plugin-webserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bykof%2Fcordova-plugin-webserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bykof%2Fcordova-plugin-webserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bykof%2Fcordova-plugin-webserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bykof","download_url":"https://codeload.github.com/bykof/cordova-plugin-webserver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248055278,"owners_count":21040156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","cordova","http","plugin","requests","response","rest","webserver"],"created_at":"2024-10-20T12:06:27.685Z","updated_at":"2025-04-09T15:04:09.350Z","avatar_url":"https://github.com/bykof.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cordova-plugin-webserver\n*A webserver plugin for cordova*\n\nThis plugin helps you to start a full webserver in JavaScript on Android and iOS.\n\n## Current supported platforms\n\n- Android (i think all versions?! Tell me if it's not true)\n- iOS (8.0 or later (armv7, armv7s or arm64))\n\n## Why?\n\nI started this project because I wanted a solution like [ExpressJS](http://expressjs.com/de/) 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.\n\n## Installation\n\nJust add the cordova plugin to your project\n\n`cordova plugin add https://github.com/bykof/cordova-plugin-webserver`\n\n## Use\n\nOk so it's pretty ez. There are 4 Methods which are available in the `webserver` variable:\n\n- start(port) or start()\n- stop()\n- onRequest(request)\n- sendResponse(responseId, responseObject, callbackSuccess, callbackError)\n\n### start(port)\n\nport (optional): Set a port of your webserver.\nDefault port: 8080\n\nThis method will start your webserver.\n\n### stop()\n\nThis method will stop your webserver.\n\n### onRequest(callback(request))\n\nEvery time the webserver receives an request your callback function is called. \nThe request params will look like this:\n```\n{\n\trequestId: '3jh4-ku34k-k3j4k-k3j42',\n\tbody: '',\n\theaders: {\n\t\t... some headers\n\t},\n\tmethod: 'POST',\n\tpath: '/hello/world',\n\tquery: 'bla=wer\u0026blu=2'\n}\n```\n\n### sendResponse(requestId, responseObject,  callbackSuccess, callbackError)\n\nIf you received a request you will probably send a response \"*cough*\"...\nWe 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).\n\nThe params have to look like this (there are not default values for the params!):\n```\n{\n\tstatus: 200,\n\tbody: '\u003chtml\u003eHello ... something\u003c/html\u003e',\n\theaders: {\n\t\t'Content-Type': 'text/html' \u003c--- this is important\n\t}\n}\n```\n\n#### Serving files\n\n\nTo serve a file in response to an http request you should use `path` param which points to the file\nlocation on the device. \n\n```\n{\n\tstatus: 200,\n\tpath: '/sdcard0/Downloads/whatever.txt',\n\theaders: {\n        }\n}\n```\n\nThe cordova-plugin-file plugin can be used to locate the path of the file data to be sent. For android you\nmight need strip the `file://` part of the file path for it to work. \n```\nwindow.resolveLocalFileSystemURL('cdvfile://localhost/temporary/path/to/file.mp4', function(entry) {\n  console.log(entry.toURL());\n});\n```\n\n## Example\n\n```javascript\nwebserver.onRequest(\n\tfunction(request) {\n\t\tconsole.log(\"O MA GAWD! This is the request: \", request);\n\n\t\twebserver.sendResponse(\n\t\t\trequest.requestId,\n\t\t\t{\n\t\t\t\tstatus: 200,\n\t\t\t\tbody: '\u003chtml\u003eHello World\u003c/html\u003e',\n\t\t\t\theaders: {\n\t\t\t\t\t'Content-Type': 'text/html'\n\t\t\t\t}\n\t\t\t}\n\t\t);\n\t}\n);\n\nwebserver.start();\n\n//... after a long long time\n// stop the server\nwebserver.stop();\n```\n\n## Credits\n\nSpecial thanks to:\n\n- https://github.com/NanoHttpd/nanohttpd\n- https://github.com/swisspol/GCDWebServer\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbykof%2Fcordova-plugin-webserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbykof%2Fcordova-plugin-webserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbykof%2Fcordova-plugin-webserver/lists"}