{"_id":"@allencomm/rn-http-server","_rev":"1-9803bda8a888ecc5215f88817059f948","name":"@allencomm/rn-http-server","dist-tags":{"latest":"0.1.3"},"versions":{"0.1.3":{"name":"@allencomm/rn-http-server","version":"0.1.3","description":"A simple http server implementation for react native Android apps","main":"httpServer.js","scripts":{"test":"echo \"Error: no test specified\" && exit 1"},"repository":{"type":"git","url":"git+https://github.com/josiahallencomm/react-native-http-server.git"},"keywords":["react-component","react-native","android","nanohttpd"],"author":{"name":"James Strain, Josiah Brower"},"license":"MIT","bugs":{"url":"https://github.com/josiahallencomm/react-native-http-server/issues"},"homepage":"https://github.com/josiahallencomm/react-native-http-server#readme","_id":"@allencomm/rn-http-server@0.1.3","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"josiahallencomm","email":"josiahb@allencomm.com"},"dist":{"integrity":"sha512-kFBXhnajsGHUalmojtDSL38P9BLlT9ID8pVR3+bjMt7Raqds32j+JXUIJILm8PvaYZr4BHK9zL81IASVi4+caw==","shasum":"3e67822ec682f0519e2b2b2bb6c577db4ffdf2f7","tarball":"https://registry.npmjs.org/@allencomm/rn-http-server/-/rn-http-server-0.1.3.tgz","fileCount":10,"unpackedSize":19791,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcAEnpCRA9TVsSAnZWagAAagcQAImHdv4bWAbFVtCExI/l\nRK7d4oc0hINWnUp0/Rt9GGFrV6l6ljigMVeXL3h8V7bs12X80auGGp9mme1C\nA308glF8y3LIrKTbtpI6hWGnsbS/GqPuZnxzYlnX0ngh8xlc44KtBv1KSGHV\nA4SCwWsj6tm60BiAnR3boEkhVd7VyKEpQcG/fpLVU3LIlAt3fbutLBKGclkl\n1DNwkxW75ldiKaleKK2ZoKo6q9HR9Sw4nYssJNAeK+I9cKdS0WXmMDTxO3R9\nvjnaktaZHXMIeeAw+cAkngtE3xkXTlG14scVyjIZwmtZC58LIAikGfRX53pL\nbO8217o3DA5GKtJCkOGEAX/helQhi/Q8GtBs4S+gFK1acqhUyvqTDT5yhqp/\n6BCPXga+JhheqeOJmy0aElHdRvYLk1TlSHxrMzOIThX1KCId4R7LlVKmt7In\nK3TjPd9XhzU5k5mgG8Wdo4FQ8qzEfzBcjwqtrOVLh4sYNjKKAItDPyDaDGNv\npemiCUL+0+atns2gBWEV6Tlr8cR8Occi4UGx3z30qRq49HSUMFzDNQn5X0Ei\nmf8Pok7Cr5sfc6egZUCDKJ6Xdv0gopLDvtWFU4PN/RHL2vzSJ/9uA3b942xG\nQugbwS7T4a1Eq1FGpk0YK9Db/RJykzYT2mDxhefxwyf2sFs00bhF/V8gDagU\nM6/x\r\n=/aaT\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFVrqHj/6yfv/kXwcRklmHy8wBdMX84ruVjy1gnl0d0iAiEAqdvQ3b8n+RnTXwMCkWRqzwnTgo2P+zVsq+WYPaVnWu8="}]},"maintainers":[{"name":"josiahallencomm","email":"josiahb@allencomm.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/rn-http-server_0.1.3_1543522792694_0.42769529565121367"},"_hasShrinkwrap":false}},"time":{"created":"2018-11-29T20:19:52.521Z","0.1.3":"2018-11-29T20:19:52.893Z","modified":"2022-04-04T13:31:51.609Z"},"maintainers":[{"name":"josiahallencomm","email":"josiahb@allencomm.com"}],"description":"A simple http server implementation for react native Android apps","homepage":"https://github.com/josiahallencomm/react-native-http-server#readme","keywords":["react-component","react-native","android","nanohttpd"],"repository":{"type":"git","url":"git+https://github.com/josiahallencomm/react-native-http-server.git"},"author":{"name":"James Strain, Josiah Brower"},"bugs":{"url":"https://github.com/josiahallencomm/react-native-http-server/issues"},"license":"MIT","readme":"# react-native-http-server\n\n** Note: This is an experimental library and needs a bit of love if you'd like to take it to production. **\n\nHTTP Server for [React Native](https://github.com/facebook/react-native)\n\nAndroid only for now. \n\nBuilt on top of the NanoHttpd library: https://github.com/NanoHttpd/nanohttpd\n\n## Install\n\n```shell\nnpm install --save react-native-http-server\n```\n\n## Automatically link\n\n#### With React Native 0.27+\n\n```shell\nreact-native link react-native-http-server\n```\n\n#### With older versions of React Native\n\nYou need [`rnpm`](https://github.com/rnpm/rnpm) (`npm install -g rnpm`)\n\n```shell\nrnpm link react-native-http-server\n```\n\n## Manually link\n\n- in `android/app/build.gradle`:\n\n```diff\ndependencies {\n    ...\n    compile \"com.facebook.react:react-native:+\"  // From node_modules\n+   compile project(':react-native-http-server')\n}\n```\n\n- in `android/settings.gradle`:\n\n```diff\n...\ninclude ':app'\n+ include ':react-native-http-server'\n+ project(':react-native-http-server').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-http-server/android')\n```\n\n#### With React Native 0.29+\n\n- in `MainApplication.java`:\n\n```diff\n+ import com.strainy.RNHttpServer.RNHttpServer;\n\n  public class MainApplication extends Application implements ReactApplication {\n    //......\n\n    @Override\n    protected List<ReactPackage> getPackages() {\n      return Arrays.<ReactPackage>asList(\n+         new RNHttpServer(),\n          new MainReactPackage()\n      );\n    }\n\n    ......\n  }\n```\n\n#### With older versions of React Native:\n\n- in `MainActivity.java`:\n\n```diff\n+ import com.strainy.RNHttpServer.RNHttpServer;\n\n  public class MainActivity extends ReactActivity {\n    ......\n\n    @Override\n    protected List<ReactPackage> getPackages() {\n      return Arrays.<ReactPackage>asList(\n+       new RNHttpServer(),\n        new MainReactPackage()\n      );\n    }\n  }\n```\n\n\n## Release Notes\n\nSee [CHANGELOG.md](https://github.com/strainy/react-native-http-server/blob/master/CHANGELOG.md)\n\n## Example\n\nFirst import/require react-native-http-server:\n\n```js\n\n    var httpServer = require('react-native-http-server');\n\n```\n\n\nInitalise the server in the `componentWillMount` lifecycle method. When initalising, you'll provide an options object (only the `port` property is accepted for now) and a callback where requests will be captured and responses returned.\n\n```js\n\n    componentWillMount(){\n\n      var options = {\n        port: 1234, // note that 80 is reserved on Android - an exception will be thrown\n      };\n\n      // initalise the server (now accessible via localhost:1234)\n      httpServer.create(options, function(request, send){\n\n          // interpret the url\n          let url = request.url.split('/');\n          let ext = url[1];\n          let data = JSON.stringify({data: \"hello world!\", extension: ext});\n\n          //Build our response object (you can specify status, mime_type (type), data, and response headers)\n          let res = {};\n          res.status = \"OK\";\n          res.type = \"application/json\";\n          res.data = data;\n          res.headers = {\n            \"Access-Control-Allow-Credentials\": \"true\",\n            \"Access-Control-Allow-Headers\": \"Authorization, Content-Type, Accept, Origin, User-Agent, Cache-Control, Keep-Alive, If-Modified-Since, If-None-Match\",\n            \"Access-Control-Allow-Methods\": \"GET, HEAD\",\n            \"Access-Control-Allow-Origin\": \"*\",\n            \"Access-Control-Expose-Headers\": \"Content-Type, Cache-Control, ETag, Expires, Last-Modified, Content-Length\",\n            \"Access-Control-Max-Age\": \"3000\",\n            \"Cache-Control\": \"max-age=300\",\n            \"Connection\": \"keep-alive\",\n            \"Content-Encoding\": \"gzip\",\n            \"Content-Length\": data.length.toString(),\n            \"Date\": (new Date()).toUTCString(),\n            \"Last-Modified\": (new Date()).toUTCString(),\n            \"Server\": \"Fastly\",\n            \"Vary\": \"Accept-Encoding\"\n          };\n\n          send(res);\n\n      });\n\n    }\n\n```\n\nFinally, ensure that you disable the server when your component is being unmounted.\n\n```js\n\n  componentWillUnmount() {\n    httpServer.stop();\n  }\n\n```\n","readmeFilename":"README.md"}