0.0.7 • Published 10 years ago
react-native-httpserver v0.0.7
react-native-httpserver
A http server for react native that serves files from a www directory in your bundle.
Nice when you:
- want to load things into WebViews with 'http://' (instead of 'file://')
- want to use 'networked' images
Getting started
- Clone this repo into your node_modules directory
- In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] - Go to
node_modules➜react-native-httpserverand add the.xcodeprojfile - In the XCode project navigator, select your project. Add
libRNHTTPServer.ato your project'sBuild Phases➜Link Binary With Libraries - Click
RNHTTPServer.xcodeprojin the project navigator, go to theBuild Settingstab and make sureHeader Search Pathscontains both$(SRCROOT)/../../react-native/Reactand$(SRCROOT)/../../../React- mark both asrecursive. - Create a folder called
wwwin your project's top-level directory (usually next to your node_modules and index.js file), and put the files you want to access over http in there. - Add the
wwwfolder to Xcode (so it gets bundled with the app).
Usage
All you need is to require the react-native-httpserver module and then call the start method, with a port.
var http = require('react-native-httpserver');
http.start("8999");The toplevel URL then becomes http://127.0.0.1:8999/index.html, also accessible as http.url().
Implementation
Based on MongooseDaemon and the mongoose server
Mongoose is cross platform, so an Android version should be possible.
Changelog
0.0.7 Added example project
0.0.6 Added doc root option
0.0.3 Published to npm
0.0.2 Replaced GCDWebServer with Mongoose
0.0.1 IPR
TODO
- Example project
- Android version
- Better docs